The while structure is similar to that of for, but a little cleaner and we simply define the condition that indicates when the loop or cycle is going to be executed; as you can see, if we start from the for in which we had three phases, the initialization phase, the condition phase and the update phase; Here we only have one phase, therefore, we have to carry out the rest of the phases manually somewhere in our code; while offers us a more flexible structure than for, although in web development, as we always have a finite set of elements that we want to work on, generally the structure offered by for is better for us:
var n = 0
while(n < 10) {
console.log(n);
n++
}
var n = 0
while(n < 10) {
console.log(n);
n = n + 2
}
var n = 10
while(n < 10) {
console.log(n);
n = n + 2
}
Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter