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?

  1. 12 times
  2. 8 times
  3. 4 times
  4. 16 times

Java Nested for Loops

18 Likes

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 iValue of j
01
 2
 3
11
 2
 3
21
 2
 3
31
 2
 3

Answered By

9 Likes


Related Questions