C++20 sections · 1024 units
Open in Course

Boolean in Conditions

Using bool with if

You will use bool variables in if statements to control program flow. If a bool is true, the code inside the if block runs. If false, it skips. Example: bool hasAccess = true; if (hasAccess) { cout << "Welcome"; } prints "Welcome" because hasAccess is true.

Comparisons like x > 10 or name == "Alice" return bool values. You can store these: bool isAdult = age >= 18; for use later in your program.