What does the for
loop do in C?
a) It iterates over a block of code a specified number of times
b) It checks a condition at the end of the loop
c) It initializes variables but does not loop
d) It only iterates once
Answer:
a) It iterates over a block of code a specified number of times
Explanation:
The for
loop in C is a control flow statement that allows code to be executed repeatedly based on a condition. It is typically used when the number of iterations is known before entering the loop. The for
loop consists of three parts: initialization, condition, and increment/decrement. The loop continues to execute as long as the condition remains true. After each iteration, the increment or decrement step is performed, and the condition is checked again. This structure makes the for
loop highly flexible and suitable for a wide range of iterative tasks.
Understanding the for
loop is essential for performing repetitive tasks efficiently in C programming.