In this task we have to help the frog cross a busy road. We could just charge straight across the road but its more than likely well get run over, so we need to do things in a more controlled way. The instructions well use are:
| frogRight(numberOfSteps) | Moves the frog numberOfSteps to the right |
| safeOnRight() | Evaluates to true if there is no traffic approaching from the right |
| nextToRoad() | Evaluates to true if the frog is directly next to a road |
We will use the instruction frogRight() to move up to the edge of the road. Then we will loop while nextToRoad() evaluates to true:
while( nextToRoad() )
{
}
In that loop we will test if the road is safeOnRight(). If it is, we will move the frog right. This will cause nextToRoad() to evaluate to false, causing the loop to end.
Write a program to help the frog cross the road safely
Note that once the program has been written correctly, the frog will never get run over no matter how many times the program is run