CMClearMathAcademy

Logic in Computer Science and Boolean Thinking

A free Logic lesson from the “Logic Applications and Final Review” unit, with a worked example and practice problems including step-by-step solutions.

Computer programs often branch on true/false conditions. Boolean thinking makes truth tables practical. Learning objective: Connect truth values, conditionals, and and/or logic to code. Prerequisite: No formal prerequisite. Work in this lesson starts with ordinary language, then connects the idea to symbols only after the meaning is clear. Example 1: An algebra rule may apply only if a denominator is not zero. Example 2: A program condition such as 'if score >= 70 and quiz submitted' uses logic to decide what happens next. A common misconception is to treat familiar wording as proof; instead, check exactly what the statement says and what follows from it.

What you'll learn

Why it matters: Logic transfers to algebra, geometry, statistics, computer science, AI prompts, and clear written explanations.

Worked example

Problem. Example case A (Logic in Computer Science and Boolean Thinking): Worked example: Code runs when isLoggedIn (True) AND isAdmin (True). Does it run?

  1. && means both must be true.
  2. isLoggedIn is True; isAdmin is True.
  3. So the AND condition is True.

Answer: True

Lesson preview: this page shows 5 practice items. The interactive activity contains 20 practice items and 10 quiz items (multiple choice). Counts include repeated prompts and variants.

Practice problems

1. Practice case A (Logic in Computer Science and Boolean Thinking): Practice: Code runs when isLoggedIn (True) AND isAdmin (True). Does it run?

Choices: True · False

Show solution
  1. && means both must be true.
  2. isLoggedIn is True; isAdmin is True.
  3. So the AND condition is True.

Answer: True

2. Practice case B (Logic in Computer Science and Boolean Thinking): Practice: A page is shown when isOwner (True) OR isEditor (True). Is it shown?

Choices: True · False

Show solution
  1. || means at least one must be true.
  2. isOwner is True; isEditor is True.
  3. So the OR condition is True.

Answer: True

3. Practice case C (Logic in Computer Science and Boolean Thinking): Practice: A warning shows when NOT isSaved. isSaved is True. Does the warning show?

Choices: True · False

Show solution
  1. ! flips the truth value.
  2. isSaved is True.
  3. So !isSaved is False.

Answer: False

4. Practice case D (Logic in Computer Science and Boolean Thinking): Practice: Access = (hasKey AND hasPin) OR isManager. hasKey=True, hasPin=False, isManager=False. Access granted?

Choices: True · False

Show solution
  1. Evaluate the AND in parentheses first.
  2. hasKey AND hasPin is False; isManager is False.
  3. The OR result is False.

Answer: False

5. Practice case E (Logic in Computer Science and Boolean Thinking): Practice: In code, !(a && b) is equivalent to:

Choices: !a || !b · !a && !b · a || b · a && !b

Show solution
  1. This is De Morgan's Law in code.
  2. NOT of (a AND b) becomes (NOT a) OR (NOT b).
  3. The connective flips and both parts are negated.

Answer: !a || !b

Practice this interactively with instant feedback and an AI tutor.

Practice Logic in Computer Science and Boolean Thinking Take the free placement check

More Logic lessons