Scratch Lab #2

Name: Daniel Harris

Period: 7

Assignment: Lab #2

Lab Overview

This lab focused on loops and repition in Scratch. We learned about forever loops and repeat loops, and how they affect the code we run inside them. Loops can be useful when you want something to happen in increments, or if you want your program to do the same thing without writing it out multiple times. The different types of loops included forever loops, repeat _____ times loops, and repeat until loops, to name a few. Click HERE for the full description.

My Solution 1

My first problem was to make a regular hexagon with repeat commands, so I began by creating a sprite that was a horizontal line segment below the center of the sprite canvas. I then used the stamp command, which leaves behind a copy of the sprite, in combination with a turn sixty degrees command. Both of these commands were inside a repeat 5 times command to make a regular hexagon when the green flag is clicked.

Problem 2 Link

My Solution 2

The second problem was to decide which loop structure would result in a sprite moving 100 steps. The loop structures included; a move 10 steps in a repeat 10 times, a move one step within a repeat 10 times within a repeat 10 times, a move 5 steps within a repeat 16 times after a move one step, all inside a repeat 20 times, a move 1 step within a repeat 20 times preceding a move 5 steps repeated 16 times, and a move 10 steps within a repeat 10 times in a repeat forever. To solve this I made 6 cats, one of them moving 100 steps (the bottom cat) and I started all at the same x coordinate to see which ones stopped at the same spot.

>

Problem 3 Link

My Solution 3

The final problem I did was to create a program that broadcasted a message and began another animation after receiving the broadcast. To do this I created two main sprites, one was a plane that begins at the top left corner of the screen and glides to the wall on the right after the green flag is clicked. It then broadcasts message one, giving the command to show the beach ball starting at where the plane just hid and glide to the floor.

Problem 4 Link

Questions

  1. What are the types of loops contained in Scratch? What are the differences?
    • There are loops that allow you to select how many times to repeat the code inside it, loops that repeat forever, and loops that repeat until a certain action occurs or condition is met.

  2. If you are given a situation where you want an action to repeat, but you don’t know how long it should repeat for, which loop is the best structure to use? Why?
    • The best loop command is one where you can enter the number of times you want it to repeat because you can experiment with the number until you find out how many times you want the loop to repeat.

  3. Does the following loop structure work? Does it make sense? Why or why not?
    • The loop structure does not work, the command to say forever loop will only be read once because the program will read it once and enter the second forever loop, which it will not stop reading or go back to the beginning of the first one.

  4. How can sprites “know” when to begin an action? Is there more than one way?
    • Sprites “know” when to begin an action because actions are started after an event block is read when that event occurs. There are several types of command loops such as “when green flag is clicked,” “when (key) is pressed,” “when this sprite is clicked” to name a few.

  5. Are the following code snippets equivalent? Why or why not?
    • They are equivalent, because the conditions are the same, but the order they are written in is switched. One uses a double negative to express the same condition as the other.