Jump to content

Conditional Statements (if, else if, else, switch)

From Computer Science Knowledge Base
Revision as of 19:54, 7 July 2025 by Mr. Goldstein (talk | contribs) (Created page with "=== 3.3.1 Conditional Statements (if, else if, else, switch) === Imagine you're at a crossroads, and you need to decide which way to go. Your decision depends on a condition, like "If the sign says 'Beach', go left. Otherwise, go straight." '''Conditional Statements''' are programming instructions that allow your program to '''make decisions''' based on whether a certain condition is true or false. They let your code choose different paths of execution. Here are the ma...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

3.3.1 Conditional Statements (if, else if, else, switch)

Imagine you're at a crossroads, and you need to decide which way to go. Your decision depends on a condition, like "If the sign says 'Beach', go left. Otherwise, go straight."

Conditional Statements are programming instructions that allow your program to make decisions based on whether a certain condition is true or false. They let your code choose different paths of execution.

Here are the main types of conditional statements:

  • if statement:
    • This is the simplest decision-maker. It says: "IF a condition is true, THEN do this specific action."
    • If the condition is false, the action is skipped.
    • Example: