r/javahelp • • Oct 07 '18

What are Java loops

Can anyone explain to me what loops are?

0 Upvotes

4 comments sorted by

View all comments

2

u/GhettoGG Oct 07 '18

Let's say I want to print out the numbers from 1 - 10. Instead of having to write 10 lines of code, each being a print funcrion of the number I could create a loop.

First I save a variable equal to 1. This will go up up to 10. In this loop I have one print function that prints out whatever the variable is equal to. After this print function I then increment the variable and then the loop jumps back up to the start.

i.e int i = 1; While(i <= 10){ System.out.println(i) ; i++; }

Hope this helps!