← Back to Study Guide← 返回学习指南

Trace a while loop逐步追踪 while 循环

Run one Java statement or condition check at a time. Watch n and count change.每次执行一条 Java 语句或检查一次条件,观察 n 和 count 的变化。

Code代码

  1. int n = 20;
  2. int count = 0;
  3. while (n > 1) {
  4. n /= 2;
  5. count++;
  6. }

State状态

Variable变量Value值
n20
count0
Condition条件—

Use ← and → to step. The final condition is false, so the loop stops.使用 ← 和 → 逐步运行。最后条件为假,循环结束。