Well, my native language is English and I understood the context of the comment perfectly well, the English is perfectly correct. If you remove a portion of any sentence, it is then likely to lose it's original meaning - that is what you did.
Look at the difference:
"Programming without EnableExplicit is not a mistake, but it is extremely unwise."
Advice that is delivered in a kind and friendly manner.
"Programming without EnableExplicit is not a mistake"
A Statement.
Why does this code always returns zero ?
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Why does this code always returns zero ?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Why does this code always returns zero ?
I'm glad that we've talked about it.IdeasVacuum wrote:Well, my native language is English and I understood the context of the comment perfectly well
Re: Why does this code always returns zero ?
English is not my language and since DEEPL.COM exists my english has become even worse.
Unfortunately there is no "Do : Break : EndDo" in Purebasic
With "Goto" it is not a good solution that it can come with loops to problems.
Most of the time I solve it with "Repeat : Break : Until #True", which doesn't always look clean, because you might think it is a loop.
Unfortunately there is no "Do : Break : EndDo" in Purebasic
With "Goto" it is not a good solution that it can come with loops to problems.
Most of the time I solve it with "Repeat : Break : Until #True", which doesn't always look clean, because you might think it is a loop.
Code: Select all
Procedure foo()
Repeat ; Do
Debug "Loop i"
For i = 1 To 10
If i = 5
Debug "Do not more"
Break 2
EndIf
Next
Debug "Do more"
Until #True ; EndDo
Debug "Exit"
EndProcedure
foo()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Why does this code always returns zero ?
Drifting off topic, but...
Anyone remember Gosub (followed by a line number), from some early flavours of BASIC long, long ago?
Before the days of named Procedures, this was how sub-routines were done.
GoSub executed the target code and when it was finished (Return statement, I think) it carried on with the next line of code.
And there was no Break or Continue, just GoTo.
Yes, GoTo is very powerful, and therefore should be used very carefully.
But one place I find it makes for clearer code is where there is a small forest of nested loops and deep inside I find a condition which means I want to abort the whole lot. Rather than set up a series of Break and Test at every level a simple GoTo looks cleaner to me, especially if there is not much more than a cascade of Next statements between the GoTo and its label. But I have a rule that for each label there can only be one GoTo. And, in practice they are very rare indeed.
Anyone remember Gosub (followed by a line number), from some early flavours of BASIC long, long ago?
Before the days of named Procedures, this was how sub-routines were done.
GoSub executed the target code and when it was finished (Return statement, I think) it carried on with the next line of code.
And there was no Break or Continue, just GoTo.
Yes, GoTo is very powerful, and therefore should be used very carefully.
But one place I find it makes for clearer code is where there is a small forest of nested loops and deep inside I find a condition which means I want to abort the whole lot. Rather than set up a series of Break and Test at every level a simple GoTo looks cleaner to me, especially if there is not much more than a cascade of Next statements between the GoTo and its label. But I have a rule that for each label there can only be one GoTo. And, in practice they are very rare indeed.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Re: Why does this code always returns zero ?
The "goto" function should be used with care. You must also not jump out of a procedure, as this leads to a stack problem.
You can also get out of nested loops with the "break" function.Syntax
Goto <label>
Description
This command is used to transfer the program directly to the labels position. Be cautious when using this function, as incorrect use could cause a program to crash...
Note: To exit a loop safely, you always must use Break instead of Goto, and never use it inside a Select/EndSelect block (Unless you have the ability to manage the stack yourself, correctly.)
Code: Select all
For k=0 To 10
Counter = 0
Repeat
If k=5
Break 2 ; Will exit directly from the Repeat/Until and For/Next loops
EndIf
Counter+1
Until Counter > 1
Debug k
Next
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Why does this code always returns zero ?
Yes Goto, an little example
In principle, you can run this until the CPU falls out of the socket.
In principle, you can run this until the CPU falls out of the socket.
Code: Select all
If result
search_again:
delay_1+Delay_internal(0, 1000) ; Use internal timer 0
If delay_1>delay
StopDrawing()
ProcedureReturn 0
EndIf
test_color=Random($FFFFFE, 1) ; Ignore 0 and $FFFFFF
For i=y To yy
For ii=x To xx
If test_color=Point(ii, i)
Goto search_again
EndIf
Next ii
Next i
StopDrawing()
ProcedureReturn test_color
Else
ProcedureReturn -17
EndIf
地球上の平和
Re: Why does this code always returns zero ?
Surely do! An early introduction to modular programming.eck49 wrote:Anyone remember Gosub (followed by a line number), from some early flavours of BASIC long, long ago?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Why does this code always returns zero ?
@Saki
Breaks one of my old rules: Goto always goes forward, ie lower down the code. Going backwards implies either a potential loop or badly organised code. As, I think, was your point.
Breaks one of my old rules: Goto always goes forward, ie lower down the code. Going backwards implies either a potential loop or badly organised code. As, I think, was your point.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)