Think in conditionals if it's yes, it's yes; if not, it's no.

10 min · No prior experience · Lógica

A 10-minute lesson: what a condition is, its two branches, the = vs == comparison, typical cases, and a vending-machine challenge.

What a condition is, how to choose between two branches, and why = doesn't compare like ==

The case

If it rains, umbrella. If it doesn't rain, nothing. That's already a conditional.

In 10 minutes you'll read any «if… then… if not…» like a machine: condition, yes branch, and no branch. And you'll learn to dodge the trap of = vs ==.

What you will learn

  • Explain what a condition decides
  • Predict the yes or no branch of any rule
  • Spot the mistake of using = instead of ==

The crossroads

A conditional is a fork with two exits. Every program and every decision rule works this way.

  1. Condition

    The question that only accepts yes or no.

  2. Yes branch

    What happens if the condition holds.

  3. No branch

    What happens if it doesn't hold (else).

  4. The trap

    Compare properly: = assigns, == compares.

Frequently asked questions

What is a conditional in a nutshell?

A question with two exits: if the condition holds, one branch runs; if not, the other runs. There's no third option.

Why does «1 = 1» error out in many languages?

Because = assigns a value, it doesn't compare. To ask whether two things are equal, you use ==.

Test yourself: Lightning test: clear paths

A condition can only decide…

Correct answer: whether it holds or not: two branches.

A condition is a yes-or-no question. Its answer picks between the yes branch and the no branch.

Age 17 and the rule age >= 18. Does it pass?

Correct answer: No: 17 doesn't reach 18.

The condition compares against 18: 17 >= 18 is false, so the no branch runs and it doesn't pass.

Balance 20, price 20, balance >= price. Do you buy?

Correct answer: Yes: 20 is enough to pay 20.

The >= operator includes equality: 20 >= 20 is true, the yes branch opens, and it buys.

The pocket rule — Every conditional asks one thing with two exits: it holds → one branch, it doesn't → the other. Comparing uses ==; = only assigns.

What you take away

Predict what a conditional (if…, if not…) does in any case, without hesitating.

Keep learning

Open the interactive lesson →