For Loops in JavaScript (OCR A-Level Computer Science): Revision Notes
📚 Revision Notes
For Loops in JavaScript
Overview
Loops are used to repeat a block of code a specific number of times, making them useful for tasks involving fixed repetitions.
Key Concepts
- Syntax: for(initialisation; condition; increment){ code }
lightbulbExample
Example:
for (let i = 0; i < 5; i++) {
console.log("This is loop iteration " + i);
}
Common Mistakes
- Incorrect loop conditions: Ensure the condition allows the loop to exit.
infoNote
Key Takeaways
- Loops are best for tasks with a fixed number of iterations.