Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Analyze the given program segment and answer the following questions :
(i) Write the output of the program segment
(ii) How many times does the body of the loop gets executed?
for(int m=5; m<=20; m+=5)
{
if(m%3 == 0)
break;
else
if(m%5 == 0)
System.out.println(m);
continue;
}
Answer:
Analysis:
for(int m=5; m<=20; m+=5)
{
if(m%3 == 0)
break;
else
if(m%5 == 0)
System.out.println(m);
continue;
}
The loop entry will happen with m=5
m%3 == 0 will be false so it will go to else
m%5==0 will be true so m will be print as 5 and a newline will come.
loop will go to next increment section as continue is there
m+=5 will make m=10
m%3 == 0 will be false so it will go to else
m%5==0 will be true so m will be print as 10 and a newline will come.
loop will go to next increment section as continue is there
m+=5 will make m=15
m%3 == 0 will be true now so loop will break. But this is 3rd execution of loop
i) So output would be 5 10
ii) Execution count would be 3
C. Sir| Created: 31-Mar-2018 | Updated: 21-Apr-2026|ICSE2016