Question:

How many types of loop are there in C++ ?

Show Hint

The main three are `for`, `while`, and `do-while`. The newer range-based `for` loop is just a more convenient way to write a standard `for` loop for iterating over collections.
  • 2
  • 3
  • 4
  • 1
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: List the fundamental loop structures in C++. C++ provides three primary loop statements:

for loop: Used for iterating a specific number of times.
while loop: An entry-controlled loop that runs as long as a condition is true.
do-while loop: An exit-controlled loop that runs at least once.

Step 2: Consider other loop types. Since the C++11 standard, a fourth type, the range-based for loop (`for (auto item : collection)`), was introduced. However, it is a syntactic variation of the `for` loop. Traditionally, the answer is considered to be 3. Given the options, 3 is the intended answer, referring to the three distinct keywords/structures.
Was this answer helpful?
0
0