Exit command

BlitzMax Forums/BlitzMax Programming/Exit command

(tu) ENAY(Posted 2005) [#1]
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?


(tu) ENAY(Posted 2005) [#2]
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. :)


Beaker(Posted 2005) [#3]
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)



Yan(Posted 2005) [#4]
[edit]Err...What Beaker said...[/edit]


(tu) ENAY(Posted 2005) [#5]
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.


Beaker(Posted 2005) [#6]
It's a loop label. Labels always start with # in bmax.


(tu) ENAY(Posted 2005) [#7]
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.


Beaker(Posted 2005) [#8]
After a long discussion (do a search for it), this was the agreed compromise to the problem of Exiting multiple loops.


Beaker(Posted 2005) [#9]
http://www.blitzbasic.com/Community/posts.php?topic=42894&hl=Exit


(tu) ENAY(Posted 2005) [#10]
Cheers, interesting read that.

Had a bit of chuckle though when it ended with a fight :)