390 likes | 491 Views
FOR / NEXT Loop Desk Check Demonstration. Click the mouse to go to the next slide and see the next step of the process. The algorithm we are working on appears below. The first step is to create a table to keep track of the values during the desk check. BEGIN NoOfNumbers = 10 Sum = 0
E N D
FOR / NEXT LoopDesk Check Demonstration Click the mouse to go to the next slide and see the next step of the process.
The algorithm we are working on appears below. The first step is to create a table to keep track of the values during the desk check. BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) This line does the loop. It changes counter from 1 to NoOfNumbers. Initially it sets counter to 1 and when NEXT Counter is executed, the counter goes up by 1 BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END See how the old value of Sum is added to number and the new result stored. The old value is crossed out as it has been overwritten. FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END Now we have come to the NEXT Counter line, we add one to the counter. If the counter is less than or equal to the upper limit, we repeat the loop. FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) Since we had to repeat the loop this is the line we do next. BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END Counter is still less than or equal to 10 so we do the loop again. FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END Now counter is not less than or equal to 10 so we do not do the loop again. FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END FOR / NEXT Desk Check Demonstration
Now work through the algorithm, updating values as they change. The numbers we want to average are 10,9,8,7,6,5,4,3,2,1 (average 5.5) BEGIN NoOfNumbers = 10 Sum = 0 FOR Counter = 1 TO NoOfNumbers INPUT Number Sum = Sum + Number NEXT Counter Average = Sum / NoOfNumbers PRINT Average END And that’s it (finally) – our algorithm is correct! FOR / NEXT Desk Check Demonstration