Computer Applications
Given: for(i = 0 ; i < 4 ; i++)
for(j = 1 ; j < 4 ; j++)
……………
Statement
……………
How many times the above nested loop will iterate?
- 12 times
- 8 times
- 4 times
- 16 times
Answer
12 times
Reason — The outer loop will execute 4 times. For each iteration of outer loop, the inner loop will execute 3 times. Therefore, total iterations of nested loop will be 4 x 3 = 12 times. The below table summarizes the iteration of nested loops:
Value of i | Value of j |
---|---|
0 | 1 |
2 | |
3 | |
1 | 1 |
2 | |
3 | |
2 | 1 |
2 | |
3 | |
3 | 1 |
2 | |
3 |
Related Questions
The …………… break is used to terminate the outer loop from the block of inner loop.
- level
- labelled
- unlabelled
- forced
Which of the following keywords can be used to terminate a switch case as well as a loop construct?
- continue
- void
- break
- stop
Which of the following statements is not valid for a nested loop?
- The break statement can be used to terminate inner as well as outer loop.
- The outer loop can be terminated from the block of inner loop.
- The inner loop can be terminated from the block of outer loop.
- The inner loop repeats the execution a number of times for each iteration of the outer loop.
State whether the following statement is True or False :
Nested loop contains a single loop.