Repetition in Problem Solving
Movie tickets: what if you want check whether seat row is OK, and give the user another chance if it is not?
set seatrow to 0
repeat while seatrow is max row
ask for the seat row
get seat row from the user
end repeat
(See my demo here)
Titration to a neutral pH: Assume you start out with a solution of vinegar and water (acidic). Acidic pH is less that 7, basic is greater than 7, neutral is 7.
measure pH
repeat while pH is less than 7
add a drop of sodium bicarbonate solution
measure pH
end repeat
Traffic light timing: Assume that a traffic light is supposed to stay red for 30 seconds then shift to green and stay green for 45 seconds.
set light to red
repeat 30 times
wait one second
end repeat
set light to green
repeat 45 times
wait one second
end repeat
Actually the whole "program" above should be repeated, forever (unless the police turn the light control program off)
repeat while true
set light to red
repeat 30 times
wait one second
end repeat
set light to green
repeat 45 times
wait one second
end repeat
end repeat