Skip Top Navigation Bar

Evaluating Expressions that Contain While Loops

Evaluating Expressions

Grab a Piece of Paper!

Evaluate each expression.

Verify your answer by running the code in the Java Playground.

Practice 1: Counting Loop

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Practice 2: Print number

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Practice 3: Print i

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Practice 4: Print value

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Practice 5: Counting Loop

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Practice 6: Skip Counting

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Practice 7: Nested Loop

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Practice 8: Logic Operator in Loop

  • Trace the provide code segment and predict the output.
  • Verify your prediction is correct by running the code in the Java Playground.
  • If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
  • If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?

Resources