00:01
We're trying to figure out how to translate a program with until to a program with while.
00:11
To understand this, let's look at a simple example.
00:15
Let's say we're trying to print the numbers 1 through 5.
00:19
For the until post loop version, post test loop version, we start with x equals 0, x equals x plus 1.
00:29
So for our first loop, x equals 1.
00:33
We print x and we check if x equals 5, which it doesn't.
00:39
So we go back to x equals x plus 1.
00:42
So x becomes 2, which we print.
00:46
A loop again, x equals 3.
00:49
Again, x equals 4.
00:53
And then x becomes 5.
00:56
We print 5.
00:58
And because x is equal to 5, we stop the loop there.
01:02
How would we translate this to a while post test loop? well, we start the same with x equals 0.
01:09
And then in our loop, we have x equals x plus 1.
01:15
Print x.
01:17
But what do we put in our while statement? well, we want to print the value of x when it is equal to 1, 2, 3, 4, and 5.
01:28
So we want to make sure we're printing x while x is less than or equal to 5.
01:38
That way, x starts at 0, x becomes 1...