NOTES: Loops and conditions to control program flow

Jeroo has 2 basic control structures: _________ and _________.

Example: while there is a flower ahead of the jeroo named Sam, keep picking them and hopping:

while Sam.___________(__________) 
   Sam.______() 
   Sam.______() 
end while

Example: while there is not a net ahead of the jeroo named James, keep hopping:

while ____________________________
    James.hop()
end while
 
WHILE Example: Kim picks all flowers in a line of flowers ahead, then turns left
Sub main() 
   Dim Kim as Jeroo = new Jeroo( )
   While ___________________________
      Kim.hop()
      Kim.pick()
   End While
   Kim.turn(LEFT)
End Sub 

Conditions with IF

Example: Jessica should check for a net to the right. If there is one, disable it and return to the current state. Hop one space ahead.
If ________________ 

        Jessica.turn(RIGHT)
        Jessica.toss()
        Jessica.turn(LEFT)
End If
Jessica.hop()
 
If-Else example
Have the Jeroo named Timmy check for a net straight ahead. If there is one, have him disable it and turn around. If there is not a net straight ahead, Timmy should turn right. When he finishes, Timmy must move one space forward.
If Timmy.isNet(AHEAD) then
   Timmy.toss()
   Timmy.turn(LEFT)
   Timmy.turn(LEFT) 
else 
   Timmy.________________
End If
Timmy.hop()

Sensor methods: write the if statement to be used in a Jeroo method for each of these:

  1. Does this Jeroo have any flowers?
  2. Is this Jeroo facing West?
  3. Is there a flower here?
  4. Is there another Jeroo to the left?
  5. Is there a net ahead?
  6. Is there water to the right?
  7. Is there a clear space here?
    (A clear space contains no flower, no net, no water, and no Jeroo. )
  1. _____________________
  2. _____________________
  3. _____________________
  4. _____________________
  5. _____________________
  6. _____________________
  7. _____________________

Boolean expressions: Write the code for each of these expressions:

  1. Is there water to the right of Tom?
  2. Is Alice facing North?
  3. Does Peter have any flowers?
  4. Is there a flower in the square where Anthony is standing?

Write these complete IF statements:

  1. If Ellis has flowers plant a flower, otherwise pick a flower.


  2. If there is a net ahead of Walter turn right , otherwise hop


Use the HELP feature in Jeroo to finish these notes:

  1. The if Structure: The if structure is used to define ___________________________________
  2. In the if-else Structure only ____________________________ will be executed.
  3. In the cascaded-if Structure, if all conditions are false _________________________ will be executed.
  4. The pretest while structure is used to define a block of code that will be __________________________ as long as _________________________________________.