Zero. Look at the statement
FOR DASH = 1 TO MANY
The endingValue MANY
is zero, since
this is the first time it occurs in the program.
Since it is less than the startingValue the loop body will not execute.
Here is a program that adds up each integer from
START
to FINISH
.
' Add up the integers from START to FINISH ' LET TOTAL = 0 ' TOTAL will hold the sum LET START = 1 LET FINISH = 5 ' FOR COUNT = START TO FINISH LET TOTAL = TOTAL + COUNT PRINT COUNT, "has just been added to TOTAL which is now", TOTAL NEXT COUNT ' PRINT "The total is:", TOTAL END
TOTAL
starts out at zero.
Each time the loop is executed,
COUNT
will be added to TOTAL
.
COUNT
will start out at 1 and will finish at 5.
The program will print out:
1 has just been added to TOTAL which is now 1 2 has just been added to TOTAL which is now 3 3 has just been added to TOTAL which is now 6 4 has just been added to TOTAL which is now 10 5 has just been added to TOTAL which is now 15 The total is: 15
If this is not clear, follow through the program line by line (or type it into QBasic and use the debugger.) The line
LET TOTAL = TOTAL + COUNT
is done in two steps: the right-hand side adds COUNT
to what is in TOTAL
,
then that result is put back in TOTAL
.
The variable TOTAL
is changed inside the loop body.
Doesn't this violate one of the rules for the FOR
loop?