By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Grade 4 Computer Science Study Guide: Loops and Conditionals – If-Then Logic
"If you’re playing tag and the rule is ‘If you’re tagged, you freeze for 10 seconds,’ how does the game know when to let you move again? And what if the rule changes to ‘If you’re tagged and it’s raining, you freeze for 20 seconds’—how would the game keep track of both things at once?" This isn’t just about games—it’s how computers make decisions millions of times a second, whether it’s a video game character jumping over a pit or a robot vacuum avoiding your dog’s chew toy.
Imagine you’re teaching a robot how to water your classroom’s pet plant. The robot has one job: check the soil every morning, and if it’s dry, water it for 3 seconds. But what if the soil is already wet? The robot needs rules to decide what to do next—just like you need rules to decide whether to wear a jacket (if it’s cold) or bring an umbrella (if it’s raining).
Here’s how the robot’s "brain" works: 1. Check the condition: Is the soil dry? (This is the if part.) 2. Take action if true: If yes, turn on the water for 3 seconds. (This is the then part.) 3. Skip or do something else if false: If no, move on to the next task (like checking the plant’s leaves).
Now, what if the plant needs different rules on weekends? You’d add another condition: "If it’s Saturday and the soil is dry, water for 5 seconds." The robot checks both things before deciding. This is how computers make choices—by following step-by-step if-then rules, over and over (loops), to handle complex situations.
Key Vocabulary:- Condition: A yes/no question the computer checks before acting. Example: "Is the traffic light red?" (Not "What color is the light?") - Loop: A command that makes the computer repeat an action until a condition changes. Example: A smart thermostat checks the temperature every 5 minutes (loop) and turns on the heat if it’s below 68°F (condition).- Boolean: A value that’s either true or false (like a light switch—on or off). Example: "Is the lunchbox in my backpack?" → true or false. Grade 4 note: In later grades, you’ll learn how Booleans can be combined (like "true and false" or "true or false").- Algorithm: A step-by-step set of rules to solve a problem. Example: Your morning routine is an algorithm: "If my alarm rings, then get out of bed; if my teeth aren’t brushed, then brush them; repeat until the bus comes."
How this appears in class:- Unplugged activities: Your teacher might give you a "robot" (a classmate) instructions like: "If the floor is tile, then take 2 steps; if the floor is carpet, then take 1 step. Repeat until you reach the door." - Proficient response: The "robot" follows the rules exactly, changing steps based on the floor type. - Developing response: The "robot" ignores the condition (e.g., takes 2 steps on carpet) or forgets to repeat.
Proficient response: scratch when green flag clicked forever if <key [space v] pressed?> then say [Meow!] for (1) seconds end if <key [right arrow v] pressed?> then move (10) steps end end What the teacher looks for:
scratch when green flag clicked forever if <key [space v] pressed?> then say [Meow!] for (1) seconds end if <key [right arrow v] pressed?> then move (10) steps end end
Written explanation: Prompt: "Explain how a traffic light uses loops and conditionals. Use the words condition, loop, and Boolean."
Mistake 1: Forgetting the "else"Prompt: In Scratch, make a sprite say "Hot!" if the mouse is touching it, and "Cold!" if it’s not.Common wrong response:
when green flag clicked forever if <touching [mouse-pointer v]?> then say [Hot!] for (1) seconds end end
Why it loses credit: The sprite only says "Hot!" and never "Cold!" because the else part is missing.Correct approach:
when green flag clicked forever if <touching [mouse-pointer v]?> then say [Hot!] for (1) seconds else say [Cold!] for (1) seconds end end
Mistake 2: Looping the wrong partPrompt: Make a sprite move 10 steps only when the up arrow is pressed, and stop when it’s not.Common wrong response:
when green flag clicked forever move (10) steps if <key [up arrow v] pressed?> then wait (1) seconds end end
Why it loses credit: The sprite moves constantly and only pauses when the arrow is pressed (backwards logic).Correct approach:
when green flag clicked forever if <key [up arrow v] pressed?> then move (10) steps end end
Mistake 3: Overcomplicating conditionsPrompt: Write instructions for a robot to water a plant only if the soil is dry and it’s sunny.Common wrong response: "If the soil is dry, water it. If it’s sunny, water it. If both, water it twice." Why it loses credit: The robot waters even if only one condition is true (e.g., sunny but wet soil).Correct approach: "Check if the soil is dry and it’s sunny. If both are true, water the plant for 3 seconds. If not, do nothing."
Within CS: Loops and conditionals → Functions Why it matters: A function is like a recipe (e.g., "make a sandwich"). You can call the recipe (loop) and add conditions (e.g., "if no peanut butter, use sunflower butter"). Understanding if-then logic helps you write functions that adapt to different situations.
Across subjects: If-then logic → Scientific experiments Why it matters: In science, you test hypotheses like "If I add vinegar to baking soda, then it will fizz." The if is your prediction, the then is your observation—just like a computer’s condition and action.
Outside school: Conditionals → Board game rules Why it matters: Games like Monopoly or Uno are full of hidden conditionals: "If you land on Boardwalk, then pay $1,000 rent" or "If you draw a Wild card, then choose the color." Next time you play, notice how the rules are just if-then statements in disguise!
"A smart fridge can text you: ‘If the milk is expired, then buy more.’ But what if the fridge is wrong? What other conditions should it check before sending the text? How would you design the fridge’s ‘brain’ to avoid false alarms?"
Pointer toward the answer: Think like a detective. The fridge’s first condition ("is the milk expired?") is good, but it’s missing context. What if the milk is almost expired? What if you’re on vacation? A smarter fridge might check: - "If the milk is expired and it’s been opened for 7 days, then text." - "If the milk is expired and the calendar says we’re home, then text; else, wait." This is how real-world AI makes decisions—by layering conditions to avoid mistakes. (Bonus: What happens if the fridge’s sensor is broken? How would you debug it?)
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.