0Pricing
Zig Academy · Lesson

Boolean Logic and Short-Circuiting

Combine conditions with and, or, not.

Boolean Logic and Short-Circuiting is a free Zig Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Thinking in True and False

A bool holds just two values: true or false. Boolean logic lets you combine these answers to make richer decisions in your code.

The and Operator

Zig spells logical and with the keyword and. The whole expression is true only when both sides are true; otherwise it is false.

const ok = isReady and hasFuel;

The or Operator

The keyword or gives you logical or. The result is true if either side is true, and false only when both are false.

const go = isAdmin or isOwner;

The not Operator

Negate a bool with the ! operator. It flips true into false and false into true, letting you express the opposite condition.

const stop = !isRunning;

Words, Not Symbols

Notice Zig uses the words and and or instead of && or ||. The spelled-out keywords make conditions read like plain English.

and Short-Circuits

With and, if the left side is false the right side is never evaluated. The answer is already false, so Zig skips the rest.

if (ptr != null and ptr.*.ready) {}

or Short-Circuits Too

With or, a true left side means the right side is skipped. The result is already true, so there is no need to look further.

if (cached or fetchSlow()) {}

Short-Circuit as a Guard

Short-circuiting lets the first check protect the second. You can confirm something is valid before you ever touch it.

if (i < len and items[i] != 0) {}

Order Your Conditions

Because evaluation runs left to right, put the cheap or safe check first. A smart order avoids needless work and unsafe access.

Booleans Stay Booleans

Zig keeps logic strict: and, or, and ! work only on bools. You cannot pass an integer where a true-or-false value is expected.

Combine for Clear Rules

Mix these operators to express any rule plainly. A line like canEdit and not isLocked reads almost like the policy it enforces.

const allow = canEdit and !isLocked;

Quick Check

In the expression a and b, when is b skipped?

Recap: Logic You Control

You combine bools with and, or, and !, and you know each short-circuits left to right. Order your checks well and your rules stay clear. ✅

Frequently asked questions

Is the “Boolean Logic and Short-Circuiting” lesson free?

Yes — the full text of “Boolean Logic and Short-Circuiting” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “Boolean Logic and Short-Circuiting”?

Combine conditions with and, or, not. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Boolean Logic and Short-Circuiting” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Arithmetic and Comparison Operators
  2. Overflow: + vs +% vs +|
  3. Bitwise Operators
  4. Boolean Logic and Short-Circuiting
← Back to Zig Academy