Exit command

Blitz3D Forums/Blitz3D Beginners Area/Exit command

Prym(Posted 2015) [#1]
Greetings to BlitzBasic bloggers

Is the EXIT command
brought out of the loop (For ... Next, for example)
or is it brought out all the loops in which it operates?

For .. To ..
For .. To ..
If x = 45 Then y = 54 : Exit
Next
Next

????

Thank you for this missing information in the manual.


Yasha(Posted 2015) [#2]
Exit only jumps out of one level of looping. If you want to jump out of deeply nested loops, the easiest way is to factor the loop assemblage into a separate function, and Return from it when done.

(Exit in BlitzMax gives additional options)


RemiD(Posted 2015) [#3]
An example to illustrate how it works :



Prym(Posted 2015) [#4]
Hi Yasha,
Thank you for the example .
I'm going to study it, now .

Prym


Kryzon(Posted 2015) [#5]
Can't you use Goto with a label right after the last Next?


steve_ancell(Posted 2015) [#6]
If you use GoTo then you lose the way back to the program line that jumped to the loop or function in the first place.

GoTo is OK during beginning simple initiation type stuff but not good for complex parts.


RemiD(Posted 2015) [#7]

GoTo is OK during beginning simple initiation type stuff but not good for complex parts.


If you don't know how to code in a structured way and if you don't understand how the program flows and if you don't know how to debug, maybe... Else goto Line is perfectly fine... (i already hear the repeaters scream at me : "spaghetti code ! spaghetti code !")



Same result.


Yue(Posted 2015) [#8]
For X% = 1 To 10 
   Print X%
   if X = 5 Exit
; ; Print on Screen 1 to 5 only.
next


@RemiD :D



steve_ancell(Posted 2015) [#9]
@Remid:

Why make things hard with spaghetti GoTo structures.

P.S: I do know how to code thank you very much.


RemiD(Posted 2015) [#10]
@steve_ancell>>Cool man, this is just a discussion.

An interesting fact related to goto and gosub :
I have had access to the source code of the game "Sphere Racer" (made with Blitz3d) and the code is full of goto gosub and very confusing to read, you must absolutely like spaghettis to understand it ;)
But this is also a fully functioning and finished and published game, so i guess that writing beautiful trendy oo code is not necessarily the most efficient thing if one can't finish a tool/game (aimed at everybody, even at me)


steve_ancell(Posted 2015) [#11]
I don't mind Gosub/Return but am GoTophobic.

Sorry bud, don't take it personal, I'm just having a cranky mood swing. ;-)