![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
where is STEP -1 ? 5 because FOR not executed at all 10 because FOR A=10 executed 9 because A=10 and then A-- |
#4
| |||
| |||
|
|
Silly discussion last week about the following bit of code: A = 5 FOR A = 10 TO 1 PRINT "HELLO WORLD" NEXT A PRINT A Nonsense piece of code, I kno - but what would the value of A be when it is PRINTed? jbase 4.0 = 9 jBase 4.1 = 5 OpenQM = 10 D3 = 10 I would have expected 10, others thought, maybe, 11 - but 5 or 9 - huh? I would be interested in the response from other MV flavours. |
#5
| |||
| |||
|
|
Silly discussion last week about the following bit of code: A = 5 FOR A = 10 TO 1 PRINT "HELLO WORLD" NEXT A PRINT A Nonsense piece of code, I kno - but what would the value of A be when it is PRINTed? jbase 4.0 = 9 jBase 4.1 = 5 OpenQM = 10 D3 = 10 I would have expected 10, others thought, maybe, 11 - but 5 or 9 - huh? I would be interested in the response from other MV flavours. Mike |
#6
| |||
| |||
|
|
uniVerse 10 = 5, consistent with the very telling result from running the 4-line program: FOR A = 10 TO 1 PRINT "HELLO WORLD" NEXT A PRINT A namely: Program "T3": Line 4, Variable "A" previously undefined. Empty string used. |
#7
| |||
| |||
|
|
John Henderson wrote: uniVerse 10 = 5, consistent with the very telling result from running the 4-line program: FOR A = 10 TO 1 PRINT "HELLO WORLD" NEXT A PRINT A namely: Program "T3": Line 4, Variable "A" previously undefined. Empty string used. This seems to be the result of engineer attemptS to maintain some form of local scope versus global. While in the loop the variable space referenced is the local instance while outside the loop that local instance no longer exists so the global instance is used. |
#8
| |||
| |||
|
|
Looks like jBase is anticipating loop termination and so skips directly. I wonder if jBase compiler is actually "smart" enough to not even |
#9
| |||
| |||
|
|
Tony Gravagno wrote: John Henderson wrote: uniVerse 10 = 5, consistent with the very telling result from running the 4-line program: FOR A = 10 TO 1 PRINT "HELLO WORLD" NEXT A PRINT A namely: Program "T3": Line 4, Variable "A" previously undefined. Empty string used. This seems to be the result of engineer attemptS to maintain some form of local scope versus global. While in the loop the variable space referenced is the local instance while outside the loop that local instance no longer exists so the global instance is used. That explanation didn't occur to me, so I didn't tell the whole story. FOR A = 10 TO 10 PRINT "HELLO WORLD" NEXT A PRINT A outputs: HELLO WORLD 10 even when I add A = 5 as a first line above the others. John |
#10
| |||
| |||
|
|
You are setting A equal to 10 with the FOR statement. What goes before is irrelevant, FOR assigns the value following to the variable and increments or decrements with the STEP command which defaults to +1. |
|
The D3 result is correct |
![]() |
| Thread Tools | |
| Display Modes | |
| |