The while loop will look through a block of code as long as a specified condition is met.
Let's take a look at an example we'll create a script that outputs the values of a variable as long
as the value does not exceed 20.
We will start by creating a variable to store our initial value
we'll call this variable.
I
will assign the value zero to this variable.
Now we can create our while loop
here we've instructed our script to output the value of i as long as the value does not exceed 20 The
while loop will loop over and over 19 times in this case each time it will output the value of I started
at 0 and incremented by 1
so let's go ahead and save this file and preview it in our web browser
so we can see that the value starts at 0.
That's the initial value of AI and it's incremented by 1 up until nineteen
we can modify our script if we adjust our maximum value to 40
we can now see that it goes up to thirty nine
we can also adjust the value of AI if we wanted to start the incrementing it fine
and that is how the while loop works.