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.
Task.
One is to ask the user three questions and notice that the user must submit their answer beside each
question.
So we will do just that.
Over here we can say system, dot, dot, print, not print line, because we don't want to move to
a new line.
Pick a number to count by.
Then we can say int step is equal to skin.
Next int.
All right.
Next one is pick a number to start counting from system, dot, dot, print.
End start is going to be equal to scandal next ent.
And then pick a number to count to.
So as you can see, the user is basically determining what the parameters of our loop will be.
In this case, this one, it's going to end up determining the condition.
So end stop is equal to skin dot next int.
And now we can use this information to create a for loop.
So for and I is equal to whatever the start value is, whichever number they want to start counting
from, the loop is going to keep running so long as I is smaller than or equal to the stop.
I hope you put smaller than or equal to not smaller then, because let's say they want to count up until
ten.
If you put smaller, then when I eventually does reach ten it's going to be smaller than the stop and
the four loop is not going to run.
Therefore, it won't print the number that you want to count to.
So make sure you put smaller than or equal to.
We'll break.
Point it in just a second.
And then every time the loop runs, we need to increase I by the number they want to count by the step.
So I plus equal step.
If they wanted to just count by one, then we would put in a plus plus.
But the number we count by is determined by user input.
And now we can just say system, dot, dot, print, not print line, because if you look back at the
output.
We need to print our account in a single line.
And that is all.
Now we can just visualize the runtime starting from here.
The number I will count by is, let's say, two.
The number I will start counting from, let's say, is six.
And the number I want to count to is.
How about 16?
So I is going to start by equaling six.
Six is smaller than or equal to 16, which means this four loop is going to run.
And it's going to start by printing the number six.
Beautiful.
And once we get to here, I plus equal step is going to update the value on the left eye by two.
So now I is going to equal eight.
Ten.
12.
14.
Once we get to here, 14 plus equal two is 16, which means this is going to run.
Printing six up until 16 and check it out.
We were able to start counting from six.
We counted up until 16 and steps of two.
And once you go back, 16 plus equal to is going to be 18.
18 is not smaller than or equal to 16, which means this loop is going to break and your runtime will
end.