QB64 Phoenix Edition
Next without For - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Next without For (/showthread.php?tid=3659)

Pages: 1 2


Next without For - eoredson - 05-02-2025

Is this a bug or a feature?

It keeps displaying 0 continuously..

Should it say 'Next without for'??

Code: (Select All)
10 GoTo 30
20 For l = 1 To 10
  30 Print l;
40 Next
50 End



RE: Next without For - CharlieJV - 05-02-2025

(05-02-2025, 02:19 AM)eoredson Wrote: Is this a bug or a feature?

It keeps displaying 0 continuously..

Should it say 'Next without for'??

Code: (Select All)
10 GoTo 30
20 For l = 1 To 10
  30 Print l;
40 Next
50 End
With the interpreted GW-BASIC, it gives that "Next without for" error, which makes sense.  Being interpreted, going from line 10 to line 30, the program has no idea there is a For loop going on at line 20.

QB64, though, is a compiled BASIC.  The BASIC gets transpiled to C++ before being compiled to an EXE.  We would need to dissect the C++ code to see what the compiled program is doing.


RE: Next without For - SMcNeill - 05-02-2025

The action makes sense to me.  You skip the definition stage of the FOR so it's basically a DO.. LOOP type structure with:

start = 0
finish = 0
increment = 0
i = start
DO
   PRINT i 
   i = i + increment
LOOP UNTIL i > finish

So... an endless loop of zeroes.


RE: Next without For - eoredson - 05-02-2025

That makes sense. So the following is valid:
This displays 5 and quits:

Code: (Select All)
10 l = 5: GoTo 30
20 For l = 1 To 10
  30 Print l;
40 Next
50 End



RE: Next without For - CharlieJV - 05-02-2025

(05-02-2025, 02:42 AM)CharlieJV Wrote:
(05-02-2025, 02:19 AM)eoredson Wrote: Is this a bug or a feature?

It keeps displaying 0 continuously..

Should it say 'Next without for'??

Code: (Select All)
10 GoTo 30
20 For l = 1 To 10
  30 Print l;
40 Next
50 End
With the interpreted GW-BASIC, it gives that "Next without for" error, which makes sense.  Being interpreted, going from line 10 to line 30, the program has no idea there is a For loop going on at line 20.

QB64, though, is a compiled BASIC.  The BASIC gets transpiled to C++ before being compiled to an EXE.  We would need to dissect the C++ code to see what the compiled program is doing.
Just for the giggles, here is what BAM does:

   


RE: Next without For - bplus - 05-02-2025

Quote:Is this a bug or a feature?

I say its a logic bug in your program, and the Next was not without a For the For is there!


RE: Next without For - CharlieJV - 05-02-2025

(05-02-2025, 01:02 PM)bplus Wrote:
Quote:Is this a bug or a feature?

I say its a logic bug in your program, and the Next was not without a For the For is there!

Yeah, but for an interpreter, it wouldn't know about the FOR because GOTO directed the execution flow to a point after the FOR?  So when hitting the NEXT, the interpreter is saying "hey, I haven't seen a FOR for this NEXT".


RE: Next without For - bplus - 05-02-2025

A clear case of GoTo abuse!


RE: Next without For - Kernelpanic - 05-02-2025

Kind of confusing!

My question: What are you smoking, eoredson?
My recommendation: Stay away from it!

Quote:bplus: A clear case of GoTo abuse!
Ten points!

Quote:SMcNeill: The action makes sense to me.
Sure! If I want to go from New York to Cleveland Ohio, I'll obviously take the shortcut via Miami, Florida.  Big Grin


RE: Next without For - eoredson - 05-02-2025

(05-02-2025, 03:31 PM)bplus Wrote: A clear case of GoTo abuse!
You think that's abuse? Try this:

Code: (Select All)
V = _Exit
10 Goto 10