Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Bubble Sort
#7
(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.
Reply


Messages In This Thread
Best Bubble Sort - by dbox - 10-20-2023, 07:36 PM
RE: Best Bubble Sort - by bplus - 10-20-2023, 07:43 PM
RE: Best Bubble Sort - by mnrvovrfc - 10-20-2023, 09:21 PM
RE: Best Bubble Sort - by bplus - 10-20-2023, 11:24 PM
RE: Best Bubble Sort - by NakedApe - 10-24-2023, 06:00 PM
RE: Best Bubble Sort - by bplus - 10-24-2023, 07:06 PM
RE: Best Bubble Sort - by mnrvovrfc - 10-24-2023, 07:42 PM
RE: Best Bubble Sort - by bplus - 10-24-2023, 07:59 PM
RE: Best Bubble Sort - by NakedApe - 10-31-2023, 07:30 PM



Users browsing this thread: 2 Guest(s)