🔄 Programming Loops Cheat Sheet¶
📋 Quick Reference¶
For Loop Syntax¶
Python¶
Java¶
C¶
JavaScript¶
While Loop Syntax¶
Python¶
Java¶
C¶
JavaScript¶
Do-While Loop Syntax¶
Java¶
C¶
🎯 Common Patterns¶
Counting 1 to N¶
Sum of Numbers¶
Factorial¶
Reverse Number¶
⚡ Control Statements¶
Break Statement¶
Continue Statement¶
🎪 Nested Loops¶
Pattern Printing¶
Matrix Operations¶
📊 Performance Tips¶
Optimization Guidelines¶
- ✅ Use
range()instead of list creation - ✅ Minimize operations inside loops
- ✅ Consider list comprehensions for simple operations
- ✅ Use appropriate loop types for the task
Common Pitfalls¶
- ❌ Infinite loops (missing condition update)
- ❌ Off-by-one errors in loop bounds
- ❌ Modifying collection while iterating
- ❌ Unnecessary nested loops
🔍 Debugging Checklist¶
- Loop condition is correct
- Loop variables are initialized
- Loop body updates condition
- No infinite loops
- Correct loop bounds
- Proper indentation
Last updated: Phase 3 Implementation