How many times did the loop body execute?
6 times. Remember to count that zero.
Here is the program again:
' Add up the integers from START to FINISH ' LET TOTAL = 0 ' TOTAL will hold the sum LET START = -2 LET FINISH = 3 ' 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
Here is what it prints:
-2 has just been added to TOTAL which is now -2 -1 has just been added to TOTAL which is now -3 0 has just been added to TOTAL which is now -3 1 has just been added to TOTAL which is now -2 2 has just been added to TOTAL which is now 0 3 has just been added to TOTAL which is now 3 The total is: 3
If the FOR
statement asked for
COUNT
to start at -10 and to end at +10,
what would the final total be?