Presentation is loading. Please wait.

Presentation is loading. Please wait.

 There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there.

Similar presentations


Presentation on theme: " There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there."— Presentation transcript:

1

2

3  There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there are looping control blocks that you can wrap around the script you want to repeat. › “forever” – loops until the program ends. This is basically an infinite loop as it goes on forever. › “repeat ()”- loops the specified number of times. › “repeat until < >” Repeat until the condition is True. You will use predicate blocks which can be found in the Operator Palette

4  Let’s look at the “repeat until” block a bit closer. › Just like REPEAT, it will do everything inside the C- shaped block a certain number of times.  However before it starts the loop each time, it checks to see if the condition (x > 5) is true. When this is condition is true, it will not repeat again.

5  Step 1 – Welcome Player, build Script!  Step 2 – Inform Player about their guess  Step 3 – Allow player to choose max value  Step 4 – Count number of guesses  Step 5 – Report number of guesses to player

6  Remember from Lab1, when we created a script for the sprite to ask our name!

7  Let’s look at our algorithm…

8

9  We want to give the player more information if they don’t guess correctly.  Have the sprite tell the player if the secret number is bigger or smaller than the number that they guessed.  Work with your neighbor to add to your script…

10  Remember there is more than one way to do this!

11  Change your code so that the player choose the max value, instead of the sprite choosing a number between 1 and 10  Use this maximum number as the highest number that the sprite will choose.  Hint: Make a new variable for “max” value

12  Make a variable for “max”

13  Now let’s keep track of how many guesses it takes before the player guesses the right number.  You will need a new variable for this task and will need to add to it every time a guess occurs.

14

15  When the player guesses the secret number tell them how many guesses it took, and congratulate them using their name.  Hint: Use previous variables!

16

17

18


Download ppt " There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there."

Similar presentations


Ads by Google