Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Breaking loops
#7
Have reported it here: https://github.com/boriel-basic/zxbasic/issues/953 if you want to track it.
The thing is that this is not exactly a "bug", but a feature of the (inherently) ambiguous modern BASIC grammar:
Traditionally BASIC line listings were numbered:
Code:
10 PRINT "HELLO WORLD"
20 GOTO 10

These are indeed labels. Boriel BASIC allows these for backward compatibilty, but also omtting them, or using normal (identifiers) labels instead:
Code:
START
   PRINT "HELLO WORLD"
   GOTO START

On top of that, the language grammar allows calling Sub and functions with no parenthesis. So:

Code:
START

Could be: Declaring the START label or calling START() function!
Since the compiler does not know anything about START it will try to best-guess
In your example, BREAK is not a reserved word, so your code is the same as an empty loop, with a label BREAK: declared in the center of the loop.

So it's like:
Code:
dim m(10) as byte => { 11, 22, 33, 44, 55, 66, 77, 88, 99, 100, 110 }

for i = 0 to 10
    if m( i ) = 66
        break ' This declares the label "break"
    end if
next

print "i = "; i
---
Boriel
Reply


Messages In This Thread
Breaking loops - by baltasarq - 02-07-2025, 12:28 PM
RE: Breaking loops - by boriel - 02-08-2025, 06:50 PM
RE: Breaking loops - by baltasarq - 02-08-2025, 07:48 PM
RE: Breaking loops - by boriel - 02-09-2025, 04:34 PM
RE: Breaking loops - by baltasarq - 02-10-2025, 09:23 AM
RE: Breaking loops - by boriel - 02-10-2025, 09:58 AM
RE: Breaking loops - by boriel - 02-16-2025, 05:07 PM
RE: Breaking loops - by baltasarq - 02-16-2025, 06:51 PM
RE: Breaking loops - by boriel - 02-16-2025, 09:29 PM
RE: Breaking loops - by boriel - 02-16-2025, 10:26 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)