Continued 0 Run the script again. g The fish now swims back an nd forth across the stage. The number of steps can be adjusted to change the speed at which i it moves. - Applying what you y have learned, edit the code, replacing e the repeat 200 block with the forever block, as shown. This will allow the fish to o swim back and forth until the Stop button is clicked d. when clicked forever move steps 5 if on edge, bounce Goodheart-Willcox Publisher = Run the script again. Test that the fish swims bac ck and forth until the Stop button is clicked. Also, ch he ck that the sprite is not upside down d when it turns. q Save the project t as HOE05-01 in your working folder. Try It! Imagine you are e watching a baseball game on TV V, and a bug is crawling on the screen. When it gets to the edge d of the screen, it turns 5 degrees e and keeps crawling. Write the code in Scratch to make th he bug crawl around the screen until the user clicks the Stop button. Experiment with different f steps values to adjust the sp pe ed and movement of the bug. Save the project as TI05-01 in y yo ur working folder. Section 5.2 Building Boolean Expressions Recall the algorithms used so far in this text. None of them have included decisions. The code flowed from one instruction to the next. However, in a project the flow of the code is based on decisions. Operators, variables, and values all combine to create decisions. All decisions are based on binary logic. Binary logic uses Boolean expressions to test conditions. A condition can be either true or false. Identifying Boolean Expressions Boolean expressions are quite evident when looking at the algorithm for a project. The algorithm for Hands-On Example 5.1 is, make a fish swim across the stage and when it reaches the edge turn the opposite direction. The part of the algorithm that requires a decision is “when it reaches the edge.” The condition, or question, is: is the fish at the edge of the stage? The code will keep moving the fish across the stage until this condition is true. All high-levellevel-h programming languages, such as Visual Basic, C++,+, and Java, use Boolean All h ig programming la nguages, such as Visua l Basic , C+ a nd Java, use Boolean exexpressions.p ressions . FYI FYI Copyright Goodheart-Willcox Co., Inc. Chapter 5 Decisions 103