Break statement?

Blitz3D Forums/Blitz3D Beginners Area/Break statement?

zortzblatz(Posted 2009) [#1]
Does B3D have a break statement that I can use to get out of loops?
I realise that I can do something like:

flag = false
while not (flag = true)
blahblahstuff
if blah
flag = true
endif
wend

but that I am looking for is a B3D equivalent to a break statement from other languages.


GfK(Posted 2009) [#2]
Exit



zortzblatz(Posted 2009) [#3]
Thanks gfk!


zortzblatz(Posted 2009) [#4]
Is there a way to use it in a function which is called from within a loop? Is there a way to make something like:

while blah
ThingBreak()
wend

Function ThingBreak()
exit
End Function

:valid?


Yasha(Posted 2009) [#5]
While blah
        ThingBreak():Exit
Wend

Function ThingBreak()
        ;Things other than Exit
End Function


Pretty sure that's the only way, sadly.


zortzblatz(Posted 2009) [#6]
Colon does things in b3d? I was utterly unaware of that. Is there anything in the documentation that covers this? What exactly would ThingBreak():exit do?
would it just run the function and then exit the loop? If so, how is it any different than:


While blah
ThingBreak()
exit
wend


?


Yasha(Posted 2009) [#7]
A colon simply separates statements. Effectively the Exit command is on the next line, but if you were using the commands that way it might be sensible to write it with a colon so you can see they act as one command. It's purely a matter of preference.

The exception is when used in a one-line If statement, in which things behind the colon act as though they were inside an If block - but you don't need an EndIf. It can be confusing at first.


zortzblatz(Posted 2009) [#8]
So a colon is just for readability?


Gabriel(Posted 2009) [#9]
The comma is not for readability. As Yasha said, it's to tell the compiler where your fake line breaks are. Having multiple statements on one line *could* be considered more readable, I suppose, although I personally find it less readable. It's just an option people use when they have a few very short lines in a row, exactly as Yasha had in his sample.


Zethrax(Posted 2009) [#10]
You'll find most of this information in the various documentation and tutorials that come with Blitz3D, zortzblatz. Just click the home icon on the IDE's toolbar. I recommend browsing through all that to get an overview of the language.

Also, check out the 2D and 3D samples that come with Blitz3D. Copying and pasting a program folder from one of the samples and then hacking around with the sample program, is a good way to learn the language, and learn some cool techniques. Note that some of the samples may require some dependent code and media from outside the program's folder, however.


_PJ_(Posted 2009) [#11]
I suppose you could control whether the exit should occur or not according to a value returned from a function, something along the lines of :

While blah

If (ThingBreak()) Then Exit

Wend

Function ThingBreak()
;Do Stuff
Return (CriteriaForBreak=TRUE)
End Function