Break statement?
Blitz3D Forums/Blitz3D Beginners Area/Break statement?
| ||
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. |
| ||
Exit |
| ||
Thanks gfk! |
| ||
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? |
| ||
While blah ThingBreak():Exit Wend Function ThingBreak() ;Things other than Exit End Function Pretty sure that's the only way, sadly. |
| ||
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 ? |
| ||
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. |
| ||
So a colon is just for readability? |
| ||
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. |
| ||
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. |
| ||
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 |