While Loops in JavaScript (OCR A-Level Computer Science): Revision Notes
📚 Revision Notes
While Loops in JavaScript
Overview
While loops execute a block of code repeatedly as long as a specified condition is true. They are useful for conditions-based repetition.
Key Concepts
- Syntax: while (condition) { code }
lightbulbExample
Example:
let count = 0;
while (count < 5) {
console.log(count);
count++;
}
Common Mistakes
- Infinite loops: Ensure the condition will eventually become false.
infoNote
Key Takeaways
- While loops are flexible and suitable for condition-based repetitions.