Computer Applications

Give the output of the following program segment and also mention the number of times the loop is executed.

int a,b;
for(a=6;b=4; a <= 4; a=a+ 6)
{
if(a%b==0)
break;
}
System.out.println(a);

Java

Java Iterative Stmts

ICSE 2017

42 Likes

Answer

6

The loop executes 0 times.

Working

a is initialized to 6 and as the loop condition is false before the first iteration itself so the loop doesn't execute.

Answered By

21 Likes


Related Questions