Computer Applications

How many times the given loop is executed? Give the output of the same.

for(k=10;k<=20;k+=4) 
{ 
   System.out.println(k); 
   if(k%3==0) continue; 
}       

Java Iterative Stmts

2 Likes

Answer

The loop exectes 3 times.

Output

10
14
18

Explanation

The loop starts from k = 10 and runs as long as k <= 20, increasing k by 4 each time. So, the values of k will be: 10, 14, and 18. When k becomes 22, the condition k <= 20 becomes false, so the loop stops. Hence, the loop runs 3 times.

Answered By

1 Like


Related Questions