Hands-On Example 5.1 Hands-On Example 5.1 Basic Comparison p Statement Comparison statements are very common in programming. Most programs contain dozens or hundreds of comparison statements. A sim mp le example of using a comparison statement is to test if f the location of an object matches e a condition. The algorithm for this exercise is: make e a fish swim across the stage, and d when it reaches the edge, turn the opposite direction. 1 Launch Scratch, , and delete the cat sprite. 2 Applying what you y have learned, add an underwater w backdrop to the stage. 3 Applying what you y have learned, add a fish sprite e from the library, and resize it if needed. Position the sprite on the left side of the stage, as s shown. Sprite and backdro op addede Goodheart-Willcox Publisher 4 Applying what you y have learned, change the rotation a style of the sprite to the middle setting (reverse) ). 5 Applying what you y have learned, add the when G Gr een Flag clicked block to the sprite. 6 Drag the repeat 10 block from the Control category, r and add it to the bottom of the code stack. Change the h value to 200. 7 Insert the move 10 steps block into the repeat loop, o and change the value to 5. The repeat loop is an example p of repetition control. 8 Click the Green F Fl ag button to execute the code. No ot ice how the fish moves from the left-hand side of the stage t to the right-hand side. However, th he fish gets stuck on the right-hand side. Scratch restricts the movement of a sprite to the sta ag e, and no decision-making has been set up to control what happens when it reaches the edge g of the stage. 9 Drag the if on edge, d bounce block from the Motion n category, and add it to the repeat loop after the move 5 steps block. Green Flag Continued Copyright Goodheart-Willcox Co., Inc. 102 Introduction to Computer Science: Coding