Skipping within a For Loop
#19
(10-23-2022, 03:38 PM)Dimster Wrote: :
or if there may be a couple within the controlled range is there a way to

For x = 50 to -50
     if x = 10 or x = 0 or x = -10 then Next
Next
I've seen something like this in somebody else's program which infuriated me. Even though it works and most BASIC interpreters accept it.

Using "NEXT" like that could cause outright confusion, for debugging the program many moons later or for somebody else who must look at the program, if the variable is never provided after "NEXT" and code is not commented. Try going three or more levels of "FOR... NEXT" nesting and using "NEXT" instead of "_CONTINUE". I guess the Freebasic developers dreaded that and that's why after "CONTINUE", in their product must specify which leading loop statement, just like with "EXIT". Also they have "EXIT SELECT" which I can't conceive a purpose. So much fuss only to have local variables inside an "IF... END IF" or "SELECT CASE... END SELECT" block.

Without "_CONTINUE" I found the example program in "DO... LOOP" in the Wiki very clever. Having "_CONTINUE" around makes programs more readable, however.

I have a weakness that sometimes I don't trust boolean evaluation even in Lua, which makes me write a condition that I want false so that something is executed. So often I'm doing something like:
Code: (Select All)
if a == 5 then
-- do nothing
else
-- do something important
end

In Lua could safely rewrite to "if not a == 5 then" or "if a ~= 5 then" but of course, in many program-scripts I wrote it's more complex than that. :/

(10-24-2022, 12:11 AM)Pete Wrote: :
I have to admit in some code of mine dated back to 2000 I've found the classic...

Code: (Select All)
FOR  I = 1 TO 10
IF I = 2 OR I = 8 THEN GOTO BYPASSI
PRINT I
BYPASSI:
NEXT
I have done the same thing, and I have even written a "preprocessor" for QB64 trying to fake "_CONTINUE" in that manner. It was difficult figuring out block "IF" statements which was the main reason why my attempt failed. :/
Reply


Messages In This Thread
Skipping within a For Loop - by Dimster - 10-23-2022, 03:38 PM
RE: Skipping within a For Loop - by Pete - 10-23-2022, 03:46 PM
RE: Skipping within a For Loop - by SMcNeill - 10-23-2022, 03:49 PM
RE: Skipping within a For Loop - by SMcNeill - 10-23-2022, 03:52 PM
RE: Skipping within a For Loop - by PhilOfPerth - 10-23-2022, 11:03 PM
RE: Skipping within a For Loop - by a740g - 10-23-2022, 03:54 PM
RE: Skipping within a For Loop - by SMcNeill - 10-23-2022, 03:56 PM
RE: Skipping within a For Loop - by Pete - 10-23-2022, 04:15 PM
RE: Skipping within a For Loop - by Dimster - 10-23-2022, 04:48 PM
RE: Skipping within a For Loop - by Pete - 10-23-2022, 04:58 PM
RE: Skipping within a For Loop - by OldMoses - 10-23-2022, 06:08 PM
RE: Skipping within a For Loop - by Pete - 10-23-2022, 08:30 PM
RE: Skipping within a For Loop - by Dimster - 10-23-2022, 10:02 PM
RE: Skipping within a For Loop - by Pete - 10-23-2022, 11:36 PM
RE: Skipping within a For Loop - by OldMoses - 10-23-2022, 11:48 PM
RE: Skipping within a For Loop - by Pete - 10-24-2022, 12:11 AM
RE: Skipping within a For Loop - by mnrvovrfc - 10-24-2022, 11:18 AM
RE: Skipping within a For Loop - by Dimster - 10-24-2022, 03:52 PM
RE: Skipping within a For Loop - by mnrvovrfc - 10-24-2022, 07:16 PM
RE: Skipping within a For Loop - by Pete - 10-24-2022, 04:46 PM
RE: Skipping within a For Loop - by Dimster - 10-24-2022, 06:03 PM
RE: Skipping within a For Loop - by CharlieJV - 10-24-2022, 06:19 PM
RE: Skipping within a For Loop - by Pete - 10-24-2022, 06:27 PM
RE: Skipping within a For Loop - by mnrvovrfc - 10-24-2022, 07:11 PM
RE: Skipping within a For Loop - by Pete - 10-24-2022, 08:44 PM



Users browsing this thread: 12 Guest(s)