1 / 39

FOR / NEXT Loop Desk Check Demonstration

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

unity-pope
Download Presentation

FOR / NEXT Loop Desk Check Demonstration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FOR / NEXT LoopDesk Check Demonstration Click the mouse to go to the next slide and see the next step of the process.

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

  28. 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

  29. 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

  30. 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

  31. 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

  32. 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

  33. 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

  34. 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

  35. 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

  36. 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

  37. 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

  38. 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

  39. 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

More Related