Exit command
Blitz3D Forums/Blitz3D Beginners Area/Exit command
| ||
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. |
| ||
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) |
| ||
An example to illustrate how it works : |
| ||
Hi Yasha, Thank you for the example . I'm going to study it, now . Prym |
| ||
Can't you use Goto with a label right after the last Next? |
| ||
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. |
| ||
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. |
| ||
For X% = 1 To 10 Print X% if X = 5 Exit ; ; Print on Screen 1 to 5 only. next @RemiD :D |
| ||
@Remid: Why make things hard with spaghetti GoTo structures. P.S: I do know how to code thank you very much. |
| ||
@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) |
| ||
I don't mind Gosub/Return but am GoTophobic. Sorry bud, don't take it personal, I'm just having a cranky mood swing. ;-) |