The
repeat until code block
The
“repeat until” block gave many of the students a challenge last
week. Just looking at the block it is easy to see how they were
confused. We will be using puzzle 15 of 20 in this example of the
“repeat until” block located at http://studio.code.org/hoc/15.1
Here
the steps in the repeat block are repeated until you get to the
sunflower. Here is what is what is happening in the repeat until
block above:
- Did you get the sunflower?
- If not, move forward a step and go to number 2 below.
- If yes, then you are finished so get out of the "repeat block" and eat that sunflower!
- Is there a path to the right of me?
- If yes, turn right.
- Go back to number 1 and "repeat" the steps.
1. Chris
Bosh, NBA star of the Miami Heat, explains this code block at
https://www.youtube.com/watch?v=G2hdlhDYICw.
The above section can be used as a handout to the class.
When a student successfully runs puzzle 15 and they select the Show Code button in the popup, here is the code that is displayed:
When a student successfully runs puzzle 15 and they select the Show Code button in the popup, here is the code that is displayed:
Here is a section from some JavaScript code that I created to simulate the repeat block:
Here is how that would look for each step on the maze:
I have created a JavaScript example that can be run that simulates a right turn at every 2 steps. Here is the text outcome of the file:
One
step forward....
Is there a path to my right?
No path to the right.
One step forward....
Is there a path to my right?
****************
Yes! Turn right.
****************
One step forward....
Is there a path to my right?
No path to the right.
One step forward....
Is there a path to my right?
****************
Yes! Turn right.
****************
One step forward....
Is there a path to my right?
No path to the right.
One step forward....
Is there a path to my right?
No path to the right.
****************
****************
You made it!
****************
****************
Is there a path to my right?
No path to the right.
One step forward....
Is there a path to my right?
****************
Yes! Turn right.
****************
One step forward....
Is there a path to my right?
No path to the right.
One step forward....
Is there a path to my right?
****************
Yes! Turn right.
****************
One step forward....
Is there a path to my right?
No path to the right.
One step forward....
Is there a path to my right?
No path to the right.
****************
****************
You made it!
****************
****************
No comments:
Post a Comment