Posted: 01:36pm 14 Jun 2025
Copy link to clipboard |
robert.rozee Guru

|
|
|
i don't know if this has been brought up before, but... while adding a pause/resume ability to a program, i found an interesting anomaly in the way the MX170 version of mmbasic handles DO...LOOP within single-line if statements. here is a quick works/fails example i put together: Print "expanded - works correctly" n=1 Do i=1 Print ">"; If n>0 Then Do : Print n,: i=i+1: n=n+1: Loop Until (i>8) Or (n>52) EndIf Print Loop Until n>52
Print Print "compact - Do's get mixed up" n=1 Do i=1 Print ">"; If n>0 Then Do : Print n,: i=i+1: n=n+1: Loop Until (i>8) Or (n>52) Print Loop Until n>52
End and here are the results of running the example: > Micromite MKII MMBasic Ver 5.05.05 Copyright 2011-2022 Geoff Graham
> RUN expanded - works correctly > 1 2 3 4 5 6 7 8 > 9 10 11 12 13 14 15 16 > 17 18 19 20 21 22 23 24 > 25 26 27 28 29 30 31 32 > 33 34 35 36 37 38 39 40 > 41 42 43 44 45 46 47 48 > 49 50 51 52
compact - Do's get mixed up > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > 11 > 12 > 13 > 14 > 15 > 16 > 17 > 18 > 19 > 20 > 21 > 22 > 23 > 24 > 25 > 26 > 27 > 28 > 29 > 30 > 31 > 32 > 33 > 34 > 35 > 36 > 37 > 38 > 39 > 40 > 41 > 42 > 43 > 44 > 45 > 46 > 47 > 48 > 49 > 50 > 51 > 52 [20] Loop Until n>52 Error : LOOP without a matching DO > essentially, the interpreter is picking up the wrong DO when the IF...THEN DO...LOOP is all on a single line. i don't really consider this a bug as such, but perhaps the manual should be appended to say that IF...THEN DO...LOOP all on one line should be avoided! btw: the code where i encountered this problem was along the lines of: Do key = Asc(Inkey$) If key=Asc("p") Then Do :Loop Until Inkey$<>"" Print Timer Loop cheers, rob :-) |