fxm wrote:Firstly, calculation of the start value:
x = x + 2 = 0 + 2 = 2
Secondly, calculation of the exit value:
exit_value = x + 7 = 2 + 7 = 9
I have no doubt that it has been implemented like that. Equally logical, natural, whatever adjective you want to use to defend this choice:
Firstly, calculation of the start value:
x = x + 2 =
0 + 2 = 2
Secondly, calculation of the exit value:
exit_value = x + 7 =
0 + 7 = 7
It's a rare case, of course, so it is understandable that this behaviour is not properly documented. How do other languages behave?
YaBasic:
Code: Select all
ct=0
for ct=ct+2 to ct+7
print ct
next
Prints a "2" and stops
SmallBasic:
Code: Select all
n=0
for n=n+2 to n+7
print n
next n
Endless loop
MasmBasic:
Code: Select all
For_ ct=ct+2 To ct+7
Print Str$(ct), " "
Next
2 3 4 5 6 7
Javascript:
Code: Select all
var i=0;
for (i = i+2; i < i+7; i++) {
text += i + "<br>";
}
Hangs and freezes the browser
Python 3:
Code: Select all
x=0
for x in range(x+2, x+7):
print(x),
2 3 4 5 6
C:
Code: Select all
int i=0;
for (i=i+2; i<i+7; i++) printf("%i ", i);
Endless loop
O2Basic:
2 3 4 5 6 7 8 9 (hey, this looks
logical because it looks like the FreeBasic output!)
Liberty Basic:
2 3 4 5 6 7