Computer Science, asked by Akshat591, 1 year ago

Difference b/w for loop and while loop in Java?

Answers

Answered by siddhartharao77
3
when u know the number of iterations u have to perform, use for loop.

When u are not sure about the iterations but you know what the condition is and you can loop that block until the condition is false.


Ex:  int a = 10;
       for(b = 1;b < = a; b++)
        {
       S.O.P(b);
       }

      

int a = 10;
int b = 1;
while(b <= a)
{
S.O.P(b);
}


Hope this helps!

Similar questions