Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review of Previous Lesson

Similar presentations


Presentation on theme: "Review of Previous Lesson"— Presentation transcript:

1 Review of Previous Lesson
28/06/2019 Review of Previous Lesson State as many Vocabulary words and Learning Objectives that you remember from the last lesson as you can. Remember to grade yourself from

2 28/06/2019 Loops / Iteration while

3 Language Features and other Testable Topics
28/06/2019 Tested in the AP CS A Exam Control Statements while

4 while loop while(condition) { } statement(s); 28/06/2019
for loop while loop for ( initialize ; test ; change ) { loopBody; } initialize; while ( test ) { change 28/06/2019 Note: with the change at the end of loop, both loops will work exactly the same with same start & end points. while(condition) { statement(s); } Condition is evaluated first and if it returns true then the statements inside while loop execute. Possible that a while loop is not executed at all if the condition is false when 1st evaluated. When condition returns false, the control comes out of loop and jumps to the next statement after while loop. Need to use increment or decrement statement inside a while loop so that the loop variable gets changed on each iteration, and at some point condition returns false. Note that where you place the ++ or -- will affect the how the loop starts or terminates. gatekeeper Note: while loops are more flexible than for loops as they do not need to be counting loops, they can also be “result-controlled”.

5 while loop – position of the change issues
28/06/2019 while loop – position of the change issues for loop while loop for ( initialize ; test ; change ) { loopBody; } initialize; while ( test ) { change If the change is placed at the beginning of a while loop, the results will appear to start and end above what might be expected when compared directly to a for loop. As the change will happen before the loop starts/1st iteration rather than before the 2nd iteration as compared to a for loop or a while loop with the change at the end. Make sure you are comfortable with both positions (and intermediate positions if necessary).

6 while loop 28/06/2019 ? When will this loop end?
Output: ? When will this loop end? This loop would never end, its an infinite while loop. This is because condition is i>1 which would always be true as we are incrementing the value of i inside while loop.

7 28/06/2019 Evaluation Say that during a run of a program, the body of a loop was executed 5 times. How many times was the condition part of the while statement evaluated? Six times. For the loop body to have executed five times, the condition had to evaluate to true five times. Then the condition was evaluated one more time, this time yielding false. ?

8 28/06/2019 Write your own programs: Write your own programs from “scratch”. Of course you should use previous programs for reference, but write your code from “scratch” (do not copy and paste).

9 Change for loops to while loops
28/06/2019 Change for loops to while loops Change some previous programs using for loops so that they use while loops until you feel confident. I also suggest changing some of these while loop programs back so that they use for loops as well.

10 6/28/2019 Grade yourself Grade yourself on the vocabulary and learning objectives of the presentation.


Download ppt "Review of Previous Lesson"

Similar presentations


Ads by Google