I'm a Scratch Coder

I'm a Scratch Coder — page 3
LOOPS If you want your code to do something over and over again it’s much quicker to use a loop The repeat loop in Scratch allows you to repeat some code a specific number of times To practice let’s draw a simple square STEP 1 DRAW A SQUARE when clicked pen down repeat 4 When the green flag is clicked Put the pen down to draw when the cat sprite moves Start a loop that will repeat 4 times one for each side move 100 steps turn 90 degrees Move the cat sprite forward 100 steps Turn the cat sprite right 90 degrees Keep repeating a When you run your code by clicking the green flag you should see the cat sprite draw a square on the screen Try to change your code to make the square bigger Now make it smaller Can you add more code to draw another square below it STEP 2 LOTS OF SQUARES a If you want to draw lots of squares you could make another loop that fits around the first loop After each square is drawn it will turn the cat sprite 15 degrees before drawing the next one Change your code so it looks like this when clicked set size to 50 clear pen down repeat 24 repeat 4 When the green flag is clicked Make the cat sprite 50 of its normal size so it doesn’t get in the way Clear the screen to remove any previous patterns Put the pen down to draw Start a loop that will repeat 24 times one for each square Start a loop that will repeat 4 times one for each side move 50 steps turn 90 degrees Move the cat sprite forward 50 steps Turn the cat sprite right 90 degrees turn 15 degrees End of the loop go back to repeat Turn right 15 degrees so the next square is in a different place Keep repeating 6