### C Loops MCQ

Loops form the backbone of many algorithms and routines in the C language. They allow you to run a section of code repeatedly until a certain condition is met. If you're eager to test your knowledge of C loops, you're in the right place! Let's dive into this multiple-choice quiz.

Each question is followed by the correct answer and an explanation to help reinforce your knowledge.

## 1. Which keyword is used to declare a loop that runs a set number of times?

a) do
b) while
c) for
d) loop

c) for

### Explanation:

The 'for' loop is used to iterate a section of code a specified number of times.

## 2. How many times will the following loop run?

``for(int i=0; i<5; i++) { ... }``
a) 0 times
b) 4 times
c) 5 times
d) Infinite times

c) 5 times

### Explanation:

The loop starts with i=0 and runs until i<5 .="" 5="" hence="" it="" iterate="" p="" times.="" will="">

## 3. Which loop checks the condition before executing the code block?

a) do-while
b) while
c) for
d) None of the above

b) while

### Explanation:

The 'while' loop checks its condition before executing its code block.

## 4. What will the following code segment print?

``````int i = 0;
do {
printf("%d ", i);
i++;
} while (i<3);``````
a) 0
b) 0 1
c) 0 1 2
d) Nothing

c) 0 1 2

### Explanation:

The loop will print values of i from 0 to 2.

## 5. Which of the following is used to forcefully exit a loop?

a) stop
b) halt
c) exit
d) break

d) break

### Explanation:

The 'break' statement is used to exit a loop forcefully.

## 6. Which statement skips the current iteration and jumps to the next iteration of the loop?

a) continue
b) skip
c) next
d) ignore

a) continue

### Explanation:

The 'continue' statement skips the current iteration and moves to the next.

## 7. How can an infinite loop be created using a 'for' loop?

a) for(;;)
b) for(int i=1; i>0; i++)
c) Both a and b
d) None of the above

c) Both a and b

### Explanation:

Both given options will result in an infinite loop.

## 8. Which loop is best for iterating over an array when you know its size?

A) for
B) while
C) do-while
D) switch

A) for

### Explanation:

The for loop is structured perfectly for iterating a known number of times.

## 9. Which of the following loops checks the condition before executing the loop body?

A) for loop
B) while loop
C) do-while loop
D) None of the above

B) while loop

### Explanation:

The while loop checks its condition before executing the loop body. If the condition is false from the start, the body may not run even once.

A) for
B) while
C) do-while
D) Both A and B