Loop Basics
What is a loop in programming?
A structure that repeats a block of code while a condition is true.
Will this loop run?
int x = 10; while(x < 5) { x++; }
No
True or False: The update statement in a for loop is optional.
True
What keyword can you use to immediately exit a loop?
break
What happens if you forget to update the loop variable?
The loop may become infinite.
What type must the loop counter be?
Any numeric type (e.g., int, double)
What do you call a loop that never ends?
An infinite loop.
True or False: You must use a counter in every while loop.
False
Fix the error:
for(int i = 1; i <= 5; i--)
Change i-- to i++ to avoid infinite loop.