If Statements
Every day you make decisions without even thinking about it. "Is it raining? Then I'll grab an umbrella." "Do I have homework? Then I'll do it before playing games." These are if statements — and they're one of the most important ideas in programming.
An if statement checks whether something is true or false. If it's true, the program does something extra. If it's false, it just skips that part and keeps going.
The Decision Diamond
In a flowchart, decisions are shown with a diamond shape. Inside the diamond, you write a question that can be answered with Yes or No (or True / False). Two arrows come out of the diamond — one for each answer.
Decision Diamond
The diamond asks a Yes/No question. Each arrow is labelled so you know which path to follow.
How an "If" Works
With a basic if statement, you only do something extra when the answer is Yes. If the answer is No, you skip it entirely and continue on. Think of it like this:
- Yes? Do the extra step, then continue.
- No? Skip the extra step, continue anyway.
Example: Checking the Weather
You're about to leave the house. You check: is it raining? If yes, you grab an umbrella. Either way, you leave the house. Step through this flowchart to see how it works.
BEGIN
IF it is raining THEN
Grab umbrella
END IF
Leave the house
Walk to school
END
See what happened? When the answer is Yes, the flowchart takes a detour to "Grab umbrella" before coming back to "Leave the house." When it's No, it goes straight down to "Leave the house" — skipping the umbrella step entirely.
Both paths meet up again. After the if statement, the flowchart continues with the same steps no matter what. The "if" only adds an optional extra step.
Another Example: Homework Check
Here's another if statement you might relate to. You get home from school and check: do I have homework? If yes, do it. Then either way, you play video games.
Notice the pattern: the diamond asks a question, the Yes path does something extra, and then both paths merge back together for the steps that happen no matter what.
Key Takeaways
- An if statement checks a condition (true/false question) and only does something when the answer is Yes.
- In a flowchart, decisions use the diamond shape. Two arrows come out — one for Yes, one for No.
- The Yes path does something extra, then rejoins the main flow.
- The No path skips the extra step and goes straight to the next step.
- In pseudocode:
IF condition THEN ... END IF