10-24-2023, 07:42 PM
(10-24-2023, 06:00 PM)NakedApe Wrote: That's cool and so few lines of code. I don't get your loop starting WHILE 1 ... WEND though. How does that work? While what's 1? Scratches head . . .
It actually creates an endless loop. It is assumed that inside the loop, there is a condition to break out of it. However, `WHILE... WEND` is not recommended to be used in this programming system simply because there is no `EXIT WHILE`. Freebasic could do that, but QB64 cannot.
Therefore, the recommended thing is:
Code: (Select All)
DO WHILE 1
'some code
IF condition THEN EXIT DO
'some more code
LOOP
With `DO... LOOP` it is also possible to do `LOOP WHILE 0` or `LOOP UNTIL 1`, then in that case you have a "loop" that executes once. This is ideal when you have a deeply-nested loop and well within, you need to break out of all the levels with `EXIT DO`. I learned about this in the QB64 Wiki.
The "condition", as bplus already said, should involve getting a keypress from the user, especially ESCAPE key, to get out of the program.