Skip to content
Adaptive

Learn Java Control Flow: Boolean Logic, Conditionals, and Iteration

Read the notes, then try the practice. It adapts as you go.When you're ready.

Session Length

~18 min

Adaptive Checks

16 questions

Transfer Probes

7

Lesson Notes

Control flow determines the order in which statements execute in a Java program. Boolean expressions evaluate to true or false using relational operators (==, !=, <, >, <=, >=) and logical operators (&&, ||, !). The if-else statement selects code paths based on conditions.

Iteration with for, while, and do-while loops repeats code blocks. For loops control initialization, condition, and update in one line. While loops check before each iteration. Nested loops enable matrix traversal and pattern generation.

Short-circuit evaluation in && and || skips the right operand when the result is already determined. These concepts form 32.5-40% of the AP CSA exam.

You'll be able to:

  • Evaluate boolean expressions using relational and logical operators
  • Trace if-else and nested conditional execution paths
  • Write and trace for, while, and do-while loops including nested loops
  • Apply De Morgan Laws to simplify compound boolean expressions

One step at a time.

Interactive Exploration

Adjust the controls and watch the concepts respond in real time.

Key Concepts

Boolean Expressions

Evaluate to true or false. Relational: ==, !=, <, >, <=, >=. Logical: && (and), || (or), ! (not).

Example: (x > 0 && x < 10) is true when x is between 1 and 9.

if-else Statements

Conditional branching. if checks condition; else provides alternative. else-if chains multiple conditions.

Example: if(score>=90) grade=A; else if(score>=80) grade=B; else grade=C;

for Loops

Repeats with init, condition, update. Executes body while condition true. Counter-controlled iteration.

Example: for(int i=0; i<5; i++) { System.out.println(i); } // prints 0-4

while and do-while Loops

while checks condition before each iteration. do-while executes body at least once, checks after.

Example: while(x>0){x--;} // may never run. do{x--;}while(x>0); // runs once min

Short-Circuit Evaluation

&& stops if left is false. || stops if left is true. Prevents unnecessary evaluation.

Example: if(arr!=null && arr.length>0) // safe: skips length if null

De Morgan Laws

!(a&&b) equals !a||!b. !(a||b) equals !a&&!b. Flip operator and negate each operand.

Example: !(x>5 && y<3) is equivalent to (x<=5 || y>=3)

Nested Conditionals and Loops

Placing if/loop inside another. Inner loop completes fully for each outer iteration.

Example: for(int r=0;r<3;r++) for(int c=0;c<4;c++) // 12 total iterations

Explore your way

Choose a different way to engage with this topic β€” no grading, just richer thinking.

Explore your way β€” choose one:

Explore with AI β†’

Concept Map

See how the key ideas connect. Nodes color in as you practice.

Worked Example

Walk through a solved problem step-by-step. Try predicting each step before revealing it.

Adaptive Practice

This is guided practice, not just a quiz. Hints and pacing adjust in real time.

Small steps add up.

What you get while practicing:

  • Math Lens cues for what to look for and what to ignore.
  • Progressive hints (direction, rule, then apply).
  • Targeted feedback when a common misconception appears.

Teach It Back

The best way to know if you understand something: explain it in your own words.

Keep Practicing

More ways to strengthen what you just learned.

Java Control Flow: Boolean Logic, Conditionals, and Iteration Adaptive Course - Learn with AI Support | PiqCue