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!
Convert the following while loop to the corresponding for loop :
int m = 5, n = 10;
while (n>=1)
{
System.out.println(m*n);
n- -;
}
Answer:
The conversion to for loop would be –
for(int m=5, n=10; n>=1 ; n- -)
System.out.println(m*n);
Notes:
Here variable m is not being changed in the loop so its initialisation can also be kept outside as
int m=5;
for(int n=10;n>=1;n- -)
System.out.println(m*n);
The brackets of loop can be given for clarity.
C. Sir| Created: 31-Mar-2018 | Updated: 22-Mar-2026|ICSE2016