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.
Welcome to Workbook 6.10.
This one seems a little long, so let's just jump right into it.
Create a for loop that runs through the length of the toppings array inside the four loop print each
index number followed by a dot.
Let's start with this because it seems really easy.
So here we've got our toppings array, which whose length depends on whatever the user inputs.
That's pretty cool, if you ask me.
So we'll say four and I is equal to zero.
I is smaller than toppings dot length.
We're going to run through the length of the toppings array and every time the loop runs we increase
the counter by one so that we go through every index in the array.
Every time the loop runs, we print each index number followed by a dot.
I'm guessing system that output print line because they're all on separate lines.
Oh no.
Beside the number, we need to pick up the user's topping.
So what we'd have to do is say print, not print line, and then we'll print the index number followed
by a dot.
And I'm guessing after we would have to print a new line so we can print a new line by either saying
print line or by just printing a new line.
Either way, it doesn't matter.
Beside the number.
Pick up the user's topping.
All right.
So after we print whatever index is currently being iterated through, we're going to say toppings at
Index II is equal to scan next line.
So whatever the user inputs we are going to store as an element inside of the toppings array, and then
we print our new line.
That should be it for task number one.
Yep.
Where did that store every topic?
The user inputs and the toppings array.
Task two is to create a for loop that runs through the length of the array and prints each topping.
So after we have registered all of the toppings they want, then we confirm with them.
So here we're going to create another for loop.
You know what?
Let's just copy this one.
Here are the toppings you ordered.
So we're just going to print line.
Whatever the current index is plus.
The topping at that index.
Is that all they want?
Beautiful.
And I think we're good.
Now you can just visualize the runtime.
I love doing that.
I'll put one here.
Alrighty.
So here scanned up next and waits for me to enter an integer.
How many topics do you want?
Let's just do what's on there in the part.
We'll say three.
So now this array is going to have a length of three based on what we inputted.
That's pretty cool.
Because each element is a string.
They start off being null.
Here we're going to change that.
So our for loop starts at I being zero.
Here we print zero.
Scan next line is going to wait for me to enter a value.
I will enter.
I don't know, Onion.
Onion is going to get picked up by scan next line and get stored as an element at index zero.
Oh God.
I press enter.
Beautiful.
Then it prints a new line.
All right, now I a plus plus takes us.
Ah, you know what?
Scan next line already moves to a new line, so I don't need this.
Let's restart the runtime.
Sorry about that.
Um.
How many topics do you want?
Three.
So I start at zero printing zero and on the same line it's asking us to input a value.
I'm going to input onion that's going to get picked up and stored as an element at index zero.
Perfect.
Now I equals one.
So I step over this scan.
Next line waits for me to enter a value.
We will enter mushroom.
That's going to get stored as an element that index one.
Now I equals to that prince scan next line is going to wait for me to enter a value.
Let's enter, Pepper.
And that's going to get stored as an element that index to I a plus plus is going to increase I to now
equal three three is not smaller than the length of the array which is also three.
So our for loop breaks.
Thank you.
Here are the toppings you ordered, and then this loop is just going to run through the length of the
toppings array and print each one.
Starting at zero.
It's going to print onion.
Now I equals one printing mushroom.
Now I equals to printing pepper.
And now I have plus plus increases.
I to be three.
Three is not smaller than the length of the array three so the four loop breaks.
And then it says, Press anything to confirm your order scan.
Next line is going to prompt me to enter anything.
Great.
A driver is on the way, scanned up close and we are done.
I really hope you enjoyed this breakpoint session.