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.
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:
What this will do is, it'll check whether
conditionis true and if it is, it'll run the code inside the curly brackets and then go back to check whetherconditionis still true. Whenconditionis false, the loop will stop.