Computing · Year 4

Branching and Decision-Making in Programs

💻 ComputingMedium14 min

Story time 📖

Tap play and I''ll read this lesson to you like a story.

0
0 of 6

🤔 you are in the . You and : IF it is , THEN I will a . I will a . You just made a ! do the thing their . This is called the a and which to . you will how that !

🧠 Key : a a ( that is or ) and then one of two . The if/ is the most way to in like .

Every if/ has . , the a with a yes or no , like 'Is the than 10?' , the IF the that run when the is yes (). , the the that run when the is no (). Only ONE each the that .

PartWhat it doesEveryday example
ConditionAsks a true-or-false questionIs it raining?
IF pathRuns when the condition is TRUEWear a coat ☔
ELSE pathRuns when the condition is FALSEWear a t-shirt 👕
The three parts of an if/else block

🔗 Match each if/else part to the correct description.

  • Condition

  • IF path

  • ELSE path

  • Selection

a by to what it will do. of as the you each in . When you an if/, you the . Is it or NOW? the , then on after the . you and your before you run it. 🕵️

How to trace a program with selection — only one path runs each time.

💡 tip: Use a to at each as you it . When you the , say 'This is or 'This is and only that . the other with your so you are not by it!

🧩 A game program checks if a player has collected 5 stars ⭐. Put these steps in the correct order to trace through the program.

  1. Skip the ELSE path and continue the program
  2. Play a winning sound 🎉
  3. The condition is TRUE, so follow the IF path
  4. Check the condition: has the player collected 5 stars?
  5. Start the program

have that make the in the way. A bug is the . For , IF is than 10 when you than 10. Another bug is the in the IF and the thing at the ! and these using .

⚠️ out for this bug: to an . If there is no , the does when the is . That be , but in a it could a a when they . ask: what should in BOTH ?

🗂️ Is each situation a bug or correct code? Sort them into the right category.

  • The IF path plays a sad sound when the player WINS

  • The condition asks 'Is lives equal to 0?' but the ELSE path (not the IF path) shows Game Over

  • IF score is greater than 10, show 'Well done!', ELSE show 'Keep trying!'

  • The program checks a condition but has no ELSE path when one is needed

  • IF it is raining, wear a coat. ELSE wear a t-shirt.

✍️ Complete these sentences about selection. Choose the correct words from the word bank.

a a and then one of two . The when the is , and the when the is .

🌍 : Every a you have , or a when to , or a when it your is the . If/ are used in every !

Quiz time! 📝

Branching and Decision-Making: Check Your Understanding

Question 1 of 5

Tip: log in to save your score and track progress.

What is in a ?

Finished?

Log in to mark this lesson complete and track your progress.