A loop that contains another loop inside its body is called:

A. Infinite Loop
B. Nested Loop
C. Recursive Loop
D. Inner Loop
Correct Answer: B. Nested Loop

In programming, a loop placed inside the body of another loop is fundamentally known as a nested loop. This structure is commonly used when iterating over multi-dimensional data structures or performing operations that require repeated iterations for each iteration of an outer loop.

  • Nested Loop (Correct): This term precisely describes the concept of one loop being contained within another.
  • Infinite Loop (False): An infinite loop is one that runs indefinitely because its termination condition is never met, not a structural description.
  • Recursive Loop (False): While recursion involves a function calling itself, it's a different concept from a loop containing another loop.
  • Inner Loop (False): "Inner loop" refers to the loop inside, but "nested loop" is the comprehensive term for the entire structure.

Leave a Comment

Scroll to Top