Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is the correct syntax for a while loop in JavaScript?

View

What is the output of the following code?

View

When does a while loop terminate?

View

What will happen with the following code?

View

What is an infinite loop in the context of a while loop?

View

What will the following code print?

View

Which of the following is true about a while loop?

View

What is the output of this code?

View

How do you stop an infinite loop in a browser?

View

What happens if the condition in a while loop is false at the start?

View

What is the correct syntax for a while loop in JavaScript?

while i < 5 { }
while (i < 5) { }
while (i < 5) do { }
while i < 5:

What is the output of the following code?

let i = 0; while (i < 3) { console.log(i); i++; }

0 1
1 2 3
0 1 2
3 2 1

When does a while loop terminate?

When the condition becomes true
When the condition becomes false
After one iteration
It runs infinitely by default

What will happen with the following code?

let i = 5; while (i > 0) { console.log(i); }

Prints 5 4 3 2 1
Runs forever
Throws an error
Prints nothing

What is an infinite loop in the context of a while loop?

A loop that runs a fixed number of times
A loop that never terminates because its condition is always true
A loop that terminates early using break
A loop that skips iterations

What will the following code print?

let i = 0; while (i < 5) { if (i === 3) break; console.log(i); i++; }

0 1 2
0 1 2 3
0 1 2 3 4
Throws an error

Which of the following is true about a while loop?

The condition is checked after the code block executes
The loop runs at least once even if the condition is false
The condition is checked before the code block executes
You cannot break out of a while loop

What is the output of this code?

let i = 0; while (i < 5) { console.log(i); i += 2; }

0 1 2 3 4
0 2 4
1 3 5
0 1 3

How do you stop an infinite loop in a browser?

Close the browser
Press Ctrl+C
Use the break keyword inside the loop
Use continue to skip iterations

What happens if the condition in a while loop is false at the start?

The loop will run once
The loop will run twice
The loop will not run at all
The loop will throw an error