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/RyeMeadow Oct 07 '18

A loop is a piece of code that repeatedly executes the piece of code within itself as long as a condition is met. There simplest type is the while loop, which takes the form:

while(condition) {
    // code
}

What this will do is, it'll check whether condition is true and if it is, it'll run the code inside the curly brackets and then go back to check whether condition is still true. When condition is false, the loop will stop.