>>Let’s see how we can use
for-loops, and while-loops. Now, in my demo I’m actually
going to be looking for the exact same output
in both just to be able to compare and contrast
and how you might will use one versus the other. So let’s start with our for-loop. We’ll say “for” and then again, “name in”, and then “people”. By the way, let me get
rid of that real quick, and let me put it in “for” and one more time highlight
the little code snippet. So if I hit “Tab” here, target list and my expression lists and my target is going to be “name”. My expression is
going to be “people”, and then now my code I’ll just simply say “Print” and then the name. Cool. So now, let me just hit
“Esc” to get it out of that mode. Then if I say my little py
and then demos.py, now, I get an error message because I don’t know
how to spell people. That’s okay. Let’s go ahead and fix that. I should have noticed
the green squiggles, and now you’ll notice
that I’m getting Christopher and Susan there. Let me just put it
in real quick print before and after hopefully
just to make that a little bit easier
to see. There we go. Voilà. So there’s Christopher
and there’s Susan. Okay. Now if I was going to
do the exact same thing, so I’m not going to print it
out the second time but do this instead with a while-loop
here’s how it would look. I’m going to say index equals zero, and it needs some form and a counter. Then I’m going to go ahead
and say while and we’ll say index is less than
the length of people. I always like to do this, if I’m going to do a while-loop, I always like to make sure that I’m putting in the change right away. So go in and say
index equals index plus one, and now let’s come back up one level, and now we’ll go ahead and say print, and then we’ll say people, and then our index. Cool. So there is all
of my code there, and now if I run this, now what you’re going
to notice is I got that exact same output of
Christopher and Susan. So in the end, that for-loop and that while-loop do the exact same thing. Let me get that uncommented. There we go. So they do the exact same thing. Like I said at the outset, you really can choose either one. For something like this, I personally would prefer
using a for-loop just because I’m going to miss
incrementing index, guaranteed. So I always try to put
that in right away, because otherwise I will forget it. But that’s how you can do for-loops and while-loops inside of Python.