Control structures: loop or do while loop - 15

- Andrés Cruz

En español
Control structures: loop or do while loop - 15

The do while is basically the same while only that the condition is evaluated at the end of everything, and with this we are guaranteeing that at least the statement or statements will be executed once; part of the previous exercise:

var n = 10
while(n < 10) {
  console.log(n);
  n = n + 2
}

Which, remember, was not executed since n is equal to 10, therefore it exceeds the condition that we placed in the while; but if we convert it to a do while:

var n = 10
do{
  console.log(n);
  n = n + 2
}while(n < 10) 

You will see that the statement is executed at least once regardless of whether the condition is initially true or false; therefore, if you need this kind of behavior in your program, do while is your choice.
 

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.