(swishing)
- Here are the solutions to the three challenges.
The first was to modify the code
so that values one through 20 were output
and the change is really simple.
You just change the 10 to a 20.
Save that change.
Build and run, and there's the numbers one through 20.
The second challenge was to modify the code
so that even values two through 20 are output,
unlike a While loop, which was shown in an earlier movie,
only one line needs to be changed.
Initialization needs to change
so that x equals 1 and then x equals x plus 2.
Save, build and run, and there are the even numbers.
Of course, to make it more readable,
I'd probably have done this change, where x equals 2,
while x is less than or equal to 20.
Then change the printf statement so that x is output itself.
That's just more readable than doing it the other way.
The final challenge was to modify the code
to display values 10, nine, eight, all the way down to one.
Here's how that change would be made.
First, x must be initialized to 10.
And then the loop must spin while x is greater than zero.
And the value of x each time must be decremented.
Save, build and run.