Now moving on to looping.
So we introduce looping in our bash scripting video and we took the for loops and we made one line for
loops and those should be familiar to you.
So for loop is just a start to finish of an inter it right.
We wanted to run that pinging scanner for example and we started at the one and we ended at 256 on our
IP suite.
Now we're going to introduce that in Python form.
And we're also going to introduce a while loop.
Now the while loop is going to come back into play later on in this course especially when we get into
the exploit development part of the course.
So a while loop just think of it that it executes as long as something is true.
So let's make a new section here we're going to do a new line as usual and we're just going to go ahead
to say something like looping and let's go ahead and start with for loops.
So we'll do four loops and note that this is just the start to finish of and iterate.
OK so let's say for example that we have a list.
OK.
Let's go back to lists and we'll say vegetables and let's just throw some vegetables in there.
You can pick whatever you want.
I'm going to do a cucumber.
I'm going to do spinach and how about cabbage cake.
And again your list can look however you want to look now for this for loop.
We're going to say for X..
And remember same thing with bash.
X can be whatever you want to call it.
You can call this for veggies call whatever you want.
I just like to use a letter because it's simple to type out.
We're going to say for x in vegetables we're just going to print x and what do we think this is going
to do.
This is going to go through this list right.
It says Save for every item in vegetables.
I want you to print that out.
So we're gonna grab cucumber we're gonna grab spinach we're gonna grab cabbage print print print.
So let's take a look at that.
Let's go ahead and save it.
We're on our script here.
You can see that it printed cucumbers spinach and cabbage.
So again you've seen this before.
Just a classic example of for.
As long as we have something to iterate through we're iterating through a list here.
And remember before again we were like sequins one through two fifty five.
We iterated through that to do our pink sweep.
So we're just iterating through something that's it really basic.
Now we also have wall loops so we'll say while loops and these execute as long as true.
So later on you're going to see something that says while True the capital while true we're going to
do something.
Don't worry about that right now.
For this example we're gonna do is we're going to say i equals 1 k and so he said there will I.
That's equal to 1.
Now let's do a while loop we're going to say Well I as less than 10 I want you to go ahead and print
out I.
And then we're going to iterate I plus equals 1.
So this should all start tying together from what you saw earlier.
Remember that we had the plus equals and we're adding one to something.
So what we're doing here is you're saying hey I equals 1.
And you know it while i is less than 10 I want you to go ahead and print out.
I then we're going to say hey I is plus equals 1.
So that means I'm now going to be two then we're gonna go back through this loop again.
Now while 2 is less than 10.
Go ahead and print out that it's to make it three 3s less than 10 over and over and over and over until
this condition is no longer true.
The second that this eye becomes 10 this loop is not no longer true and it's going to stop.
So we're gonna go ahead and save this here.
Let's go ahead and print this out and you can see that we just printed 1 3 9 as expected so you're gonna
get to see these again you're going to get examples of them again.
As of right now I just want you to understand that a for loop isn't inner it and a wall loop executes
as long as true.
OK so don't worry about how they're used quite yet just understand what they are what they mean and
then you're going to see them come up and practical examples later on it'll make a lot more sense as
we go through it.
So we're going to move on to the next video.
I'm going to go ahead and catch you over there.