Math Bonk! Learning Centre Play the game

Worksheet for the lesson Coding with Conditions · All worksheets

Coding with Conditions

Grade 4 math worksheet · mathbonk.com/learn

Name: ______________________   Date: ____________

Look

A flowchart of four steps: start with a number, halve it if it is even or add 5 otherwise, subtract 4 if the answer is more than 10, endStart with a numberif the number is even, halve itotherwise add 5if the answer is more than 10, subtract 4End
  1. Start with 12. What is the final number?
  2. Start with 7. What is the final number?
  3. Start with 20. What is the final number?

Practice

  1. Program: repeat for n = 1 to 6. If n is even, clap; otherwise, stomp. What is the 5th action?
  2. In the same program, how many claps are there altogether?
  3. If the temperature is less than 10, wear a coat, otherwise wear a T-shirt. What do you wear at exactly 10 degrees?
  4. Start with x = 8. If x is greater than 5, add 2; otherwise subtract 2. What is x now?
  5. Start with 10. Repeat 3 times: if the number is even, halve it; otherwise add 1. What is the final number?
  6. A program repeats 3 times: jump once, then repeat 4 times: clap. How many claps are there altogether?
  7. Is the condition "n is greater than 5" true when n = 5?
  8. Find the bug: "If the light is green, stop. Else, go."
  9. A program repeats 5 times: if the player scored, add 10 points, otherwise add 0. The player scored on 3 of the 5 tries. What is the final score?
  10. Start with 3. Repeat 3 times: if the number is odd, add 4; otherwise halve it. What is the final number?
  11. In a program, a condition is always one of two things. What are they?

Think it through

  1. Draw a flowchart: if it is raining, take an umbrella; otherwise wear sunglasses.
  2. Explain what "otherwise" does in a program.

Challenge

  1. Start with 15. Repeat 2 times: if even, halve; otherwise subtract 5. What is the final number?
  2. Start with 24. Repeat 3 times: if the number is even, halve it; otherwise add 1. What is the final number?

Answer key

Look

  1. 6
  2. 8
  3. 10

Practice

  1. stomp
  2. 3
  3. T-shirt
  4. 10
  5. 3
  6. 12
  7. No
  8. The rule is reversed: it stops on green and goes otherwise.
  9. 30
  10. 15
  11. true or false

Think it through

  1. A decision with two branches, each ending in an action
  2. It gives the action to take whenever the condition is false

Challenge

  1. 5
  2. 3