Iteration Learning Objective: to be able to design algorithms that use iteration.
Right Motor Forward Off Algorithm Efficiency This algorithm isn’t very efficient as it contains repeated sets of instructions. Start Stop Left Motor Forward On Delay 2 Left Motor Forward Off Right Motor Forward On Right Motor Forward Off
Right Motor Forward Off Iteration Iteration allows us to repeat sets of instructions. This algorithm repeats the same set of instructions forever. Start Left Motor Forward On Delay 2 Left Motor Forward Off Right Motor Forward On Right Motor Forward Off LOOP RightMotor.forward(off) LeftMotor.forward(on) DELAY(2) LeftMotor.forward(off) RightMotor.forward(on) ENDLOOP
Predict what this program will do: Activity 1 Here is the program code for the algorithm given on the previous slide. Predict what this program will do: Prediction: Now write this program and test it on Bobbot.
Activity 2 LOOP RightMotor.forward(on) ENDLOOP Complete this design in pseudocode for an algorithm that will make Bobbot go forwards and backwards continually. LOOP RightMotor.forward(on) ENDLOOP
Place a screenshot of your code here: Activity 3 Use Touch Develop to create the program you designed in activity 2 and test it on Bobbot. Place a screenshot of your code here:
This instructions inside this FOR loop will be repeated 10 times. FOR Loops It is also possible to repeat a group of instructions a set number of times. We use a FOR loop to do this. This instructions inside this FOR loop will be repeated 10 times. FOR X = 1 TO 10: RightMotor.forward(off) LeftMotor.forward(on) DELAY(2) LeftMotor.forward(off) RightMotor.forward(on) ENDFOR Pseudocode Program Code
Activity 4 Adapt the algorithm you designed in activity 2 so that the instructions only repeat 5 times.
Place a screenshot of your code here: Activity 5 Use Touch Develop to create the program you designed in activity 4 and test it on Bobbot. Place a screenshot of your code here:
Activity 6 Design an algorithm in pseudocode that makes Bobbot move in a zig zag like the pattern shown below:
Place a screenshot of your code here: Activity 7 Use Touch Develop to create the program you designed in activity 6 and test it on Bobbot. Place a screenshot of your code here: