Computer Science, asked by chaser721, 1 year ago

example of looping in Java

Answers

Answered by QGP
14
Here is an example of Looping:


public class Loop
{
     public static void main(String[] args)

        {           for(int i=1;i<5;i++)
           {               System.out.println(i);
           }
        }
}




Here, "for" loop has three parameters. 

int i=1 refers to declaration of a variable i and starting from i=1.

i<5 is the ending condition. When the value of i becomes 5 or more, the loop will get terminated.

i++ is the increment ocndition. It increments the value of i by 1 at the end of each iteration of the loop. 


The output would be:

1
2
3
4



Hope it helps
Purva
Brainly Community
Similar questions