0
0
Javascriptprogramming~5 mins

Loop execution flow in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of a loop in programming?
A loop repeats a block of code multiple times until a condition is met or no longer true.
Click to reveal answer
beginner
What are the three main parts of a for loop in JavaScript?
Initialization (start value), condition (when to stop), and update (how to change the value each time).
Click to reveal answer
intermediate
What happens if the loop condition is always true?
The loop runs forever, causing an infinite loop that can freeze or crash the program.
Click to reveal answer
intermediate
How does a while loop differ from a do...while loop?
A while loop checks the condition before running the code, but do...while runs the code once before checking the condition.
Click to reveal answer
beginner
What is the role of the break statement inside a loop?
It immediately stops the loop and exits it, even if the loop condition is still true.
Click to reveal answer
Which part of a for loop runs only once at the start?
ABody
BCondition
CInitialization
DUpdate
What will happen if the condition in a while loop is false at the start?
AThe loop will run infinitely
BThe loop body will not run at all
CThe loop body will run once
DThe loop will run twice
What does the continue statement do inside a loop?
ASkips the rest of the current loop iteration and moves to the next
BStops the loop completely
CRestarts the loop from the beginning
DExits the program
In a do...while loop, when is the condition checked?
AMultiple times before each iteration
BBefore the loop runs
CNever
DAfter the loop runs once
What is the output of this code?<br>
for(let i = 0; i < 3; i++) {<br>  if(i === 1) break;<br>  console.log(i);<br>}
A0
B0 1 2
C1 2
DNo output
Explain how a for loop executes step-by-step.
Think about the order of the three parts and when the code inside runs.
You got /5 concepts.
    Describe the difference between while and do...while loops.
    Focus on when the condition is checked in each loop.
    You got /4 concepts.