Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
First we have to make a for loop that counts from 0 to 19.
Easy enough.
We already know that the start is going to have to be zero.
And the for loop is going to keep running so long as AI is less than 20.
So I is still going to run for 19.
But once it reaches 20, this condition is going to be false and the loop will break.
And every single time the loop runs, we're going to increase the counter by one.
And every single time we need to just print the number, I guess easy enough.
Not going to visualize the runtime for that task.
Number two, using an if l statement mark each number as even or odd.
This is beautiful because we're going to be implementing some control flow inside of our for loop.
So every time the loop runs we're going to check if the counter modulus to.
Equals zero.
If that's the case, then we know the number is even so we can print.
I followed by the verdict.
We just have to print another line and then say even.
Otherwise we know the number is odd.
So you'll remember that Modulus returns the remainder of a division.
So if the number divided by two returns a remainder, that equals zero.
We know its even, otherwise.
It's odd.
Now let us just visualize the runtime.
Put one breakpoint over here and press debug.
So I start at zero zero divided by two returns a remainder that equals zero.
So zero is even nice.
A-plus.
Plus updates our counter by one.
One divided by two does not return a remainder of zero, so else is going to get executed, which means
the number one is odd.
A-plus plus is going to increase our counter to two.
Two divided by two returns a remainder of zero, which means two is even, and we can keep that going
until we reach 19.
And our for loop runs from 0 to 19.
Every single time it runs, it's able to evaluate if the current number is even or if that number is
odd.