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

   
Reply
#6
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!
b = b + ...
Reply
#7
(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".
Reply
#8
A clear case of GoTo abuse!
b = b + ...
Reply
#9
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
Reply
#10
(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
Reply




Users browsing this thread: 1 Guest(s)