KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Give the output of the following program segment and mention how many times the loop will execute:

int k;
for ( k = 5 ; k < = 20 ; k + = 7 )
if ( k% 6==0 )
continue;
System.out.println(k);

Java

Java Iterative Stmts

ICSE

80 Likes

Answer

Output of the program is 26 and the loop executes 3 times.

As there are no curly braces after the for loop so only the statement immediately following the loop that is the if statement is part of the for loop. Again if has no curly braces so just the continue statement is part of if. The statement System.out.println(k) is outside the loop. The below table shows each iteration of for loop in detail:

kRemarks
51st Iteration
122nd Iteration
193rd Iteration
26As the loop condition k<=20 becomes false, the loop stops iterating after 3 iterations.

Answered By

31 Likes