Once the condition is true, the code branches, and a change occurs in the processing. Another path is taken, as shown in Figure 5-3. A branch in code is a point where a decision is made and a path selected based on the decision. The Scratch Boolean expression IF on edge can be judged as true or false. Is the sprite on the edge of the stage? Yes (true) or no (false)? Consider how algorithms and binary logic are used in everyday life. How many times a day do you use these concepts? For example, when your alarm clock rings, you get out of bed. So, until “is the alarm clock ringing?” is a true statement, you stay in bed. Can you think of other examples? Other expressions that can be judged as true or false are found in algorithms. For example, the algorithm for a game called Fives is: If the roll of a six-sided die is a 5, then say “The roll is a 5.”, otherwise say “The roll is not a 5.” In the code for this algorithm, the value for the roll is stored in the variable roll. The Boolean expression begins with, IF the variable roll equals 5. This expression is true only when the value of the variable is 5. The code branches based on the condition of the expression (true or false), as shown in Figure 5-4. In this example, the value of a variable is tested by the Boolean expression, not the position of the sprite. Move sprite 10 steps Is sprite on edge? NO Reverse sprite direction YES Goodheart-Willcox Publisher Figure 5-3. A diagram for the decision-making process to determine what the sprite will do when it reaches the edge of the stage. when clicked else if then roll = 5 say The roll is 5. say The roll is not 5. set to roll pick random to 1 6 Is roll equal to 5? NO YES Say "The roll is 5." YES Is Green Flag button clicked? NO Set variable roll to a random number from 1 to 6 Say "The roll is not 5." Goodheart-Willcox Publisher Figure 5-4. The code and decision-making process for determining if a die roll is or is not five. Copyright Goodheart-Willcox Co., Inc. 104 Introduction to Computer Science: Coding