Jumping out of a loop

Blitz3D Forums/Blitz3D Beginners Area/Jumping out of a loop

Flynn(Posted 2003) [#1]
Hi. How do I move out of a loop to another specific function (as in the old BASIC 'IF... THEN GO TO...')?


Forgive me for asking so many questions, but I'm thrashing out my first bit of code at the moment and it's fun to keep adding things on the fly as they occur to me. Bit messy, but a great way to learn the basics. :D


Mustang(Posted 2003) [#2]
There is GOTO:

http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Goto&ref=2d_cat

and GOSUB:

http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Gosub&ref=2d_cat

...but i would recommend either CASE:

http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Case&ref=2d_cat

or FUNCTION:

http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Function&ref=2d_cat

...Cehck the example codes above, and decide yourself :)


Ross C(Posted 2003) [#3]
there is also a command you might need if you want to exit a for next loop. it's exit. i belive you will get a memory error if you simply jump out of a loop all the time without returning too it and finishing it.


Foppy(Posted 2003) [#4]
Jumping out of a loop using "exit" shouldn't be a problem as it is was meant to be used like that. Maybe another thing is calling functions recursively (calling one function from within another function and so on and so on), as this would slowly fill up the stack (the place where the computer remembers the status of the function you just left so that it still knows everything when you return). As long as you just keep calling functions and never return (by means of the "return" keyword or just by reaching the end of the function), this memory will not be released.


Ross C(Posted 2003) [#5]
sorry, that's what i meant. bady worded sentences :)