Exit command
BlitzMax Forums/BlitzMax Programming/Exit command
| ||
Take a look at this:-Graphics 640,480 Repeat Cls For Local column = 0 To 9 For Local row = 0 To 19 If row = 3 And column = 4 Then DrawText("row = "+row,0,0) DrawText("column = "+column,0,20) Exit EndIf Next Next DrawText("row = "+row,0,40) DrawText("column = "+column,0,60) Flip FlushMem Until KeyDown(1) I'm expecting row = 3 column = 4 row = 3 column = 4 but my results are:- row = 3 column = 4 row = 10 column = 20 Why does the exit command auto complete the remaining loop increments and not entirely break out of the loop? |
| ||
Doh! I've already discovered the problem, just by reading through my own post. I forgot to add:- If row = 3 And column = 4 Then Exit in first for loop line. STUPID ME! Move along now, nothing to see here. :) |
| ||
Or you could do it like this:Strict Graphics 640,480 Repeat Cls Local row, column #colsandrows For column = 0 To 9 For row = 0 To 19 If row = 3 And column = 4 Then DrawText("row = "+row,0,0) DrawText("column = "+column,0,20) Exit colsandrows EndIf Next Next DrawText("row = "+row,0,40) DrawText("column = "+column,0,60) Flip FlushMem Until KeyDown(1) |
| ||
[edit]Err...What Beaker said...[/edit] |
| ||
Wow that's pretty neat. Is that # like a goto branch command? Quite unusual that you have to position it at the beginning of your loops. |
| ||
It's a loop label. Labels always start with # in bmax. |
| ||
Yeah, but there's no End Loop sort of command. I'm amazed BMax knows where to jump out of both loops as to me that would jump back before the loops. |
| ||
After a long discussion (do a search for it), this was the agreed compromise to the problem of Exiting multiple loops. |
| ||
http://www.blitzbasic.com/Community/posts.php?topic=42894&hl=Exit |
| ||
Cheers, interesting read that. Had a bit of chuckle though when it ended with a fight :) |