So it's time for two very quick for loop exercises.
And just like the ones before with the wild loops you don't actually have to write any code just yet
.
So I'm going to give you two code fragments and I'd like for you to try and evaluate it mentally without
using the cons..
So here's the first one.
Take a moment pause the video if you need to and then we'll go over the solution.
So at the beginning of this loop a variable is set to zero and the loop is going to run.
While it is less than 16 and every time through we're going to add eight to.
So the first time it's going to be zero and we'll print out 0.
Then we add eight.
So the next time it's eight which is still less than 16.
So we get counted out log 8.
So it prints 0 and 8 and then it adds eight more.
So we end up with I equal to 16 which is no longer less than 16 and we're done.
So let's verify pass that and we get zero and 8.
So here's the second one.
Go ahead take a moment positive he needs to.
And then we'll go over this in just a second.
OK.
So this one you're just a string rather than just numbers.
So we have a string with a bunch of random characters.
Or maybe they're not too random we'll see.
So then we have a for loop with a variable that starts as 1 not 0 and then we're going to keep running
this Loop While itis less like a string and we're going to add two every time not just one.
So the first time through we take I can reprint the character at I from the string.
So I one.
So we're going to print H which is the second character but it has index of 1.
So then we're going to add two to I which gives us three which is still less than the length of the
string.
So we're going to print out a string of three which is E.
And then we're going to keep repeating this add too which means we're going to printout L and then another
L and then o.
So the end result is that we print every other character and that happens to spell out Hello.
So in the next set of exercises I'm going to have you start writing some four loops