0:00
Hey everyone, welcome back to Simplified
0:02
by Singum. Welcome to our Python for
0:04
beginners series. So today's exercise is
0:07
one of the most classic ones you'll ever
0:09
see. Because we are going to print hello
0:12
world not once, not twice, but 10 times.
0:16
Now you might be wondering why do we
0:18
always start with hello world. It's
0:20
simple. Hello world is like tradition in
0:23
programming. It's the first thing almost
0:25
every programmer learns when starting a
0:28
new language. And today we'll repeat it
0:30
10 times using a while loop with the
0:37
Okay, let's break the flowchart down.
0:39
First we set the counter to zero and
0:43
then we enter a loop and this loop keeps
0:48
running until the counter reaches 10.
0:51
And inside the loop, we will increase
0:55
the counter by one. Each time we go
0:58
through the loop, we print hello world.
1:02
And once the counter is no longer less
1:04
than 10, then the loop stops and the
1:10
That's it. It's like telling Python,
1:12
keep saying hello world until you have
1:17
Okay, let's now turn that flowchart into
1:20
a real code. Let's create a variable
1:23
called counter and let's give it zero
1:48
and you just increment counter
1:53
by one every in every loop.
2:06
counter equal to counter + one.
2:11
I'm just writing this in every program
2:13
whenever I use this plus equal to is
2:15
because you guys might get confused as
2:19
you know we are still in the beginning
2:20
stage. I just want you to be clear about
2:23
it how to use it until you get used to
2:25
it. I'm going to do it as much as I can.
2:28
So whenever I'm using it, I'll try to
2:30
use this comment so that you guys can
2:32
remember next time even without this
2:34
comment. If you're practicing with me in
2:37
every video, in every exercise, then you
2:38
will see this like whenever I write
2:41
this, I will write this also because it
2:44
is easy for you to understand and keep
2:46
that in mind that we can write short
2:48
notation something like this. So counter
2:50
plus equal to 1 is nothing but you are
2:53
increasing counter by one which is same
2:55
as counter equal to counter + 1. Now
2:58
let's go line by line.
3:02
So here counter equal to zero. This is
3:04
like starting our stopwatch at zero. And
3:08
while the counter is less than 10 this
3:12
says that as long as the counter is less
3:14
than 10 keep looping. So this is what
3:18
this condition is all about and inside
3:21
the loop what we want we need to print
3:24
hello world. So we are printing hello
3:27
world using the print in Python
3:30
and we are increasing counter by one in
3:34
every loop so that the counter goes to
3:36
second loop, third loop, fourth loop
3:38
until the ninth loop and then it will
3:41
print hello world. Always remember that
3:44
whenever you're looping it could be for
3:46
loop or while loop a loop or any program
3:50
always starts with zero.
3:53
So it goes from 0 1 2 3 till 9. So till
3:57
9 it will be 10 times. So it will print
4:00
the hello world for 10 times. And once
4:02
the counter hits 10 the condition
4:05
becomes false and the loop stops
4:09
So let's quickly run this program.
4:14
And let's see the output.
4:17
So if you see I've printed hello world
4:20
for 10 times. 1 2 3 4 5 6 7 8 9 10.
4:27
And there you go. Python happily prints
4:30
hello world 10 times.
4:33
Awesome. So you just learned how to use
4:36
a while loop to repeat actions in
4:38
Python. Loops are like magic. They save
4:41
you from writing the same line of code
4:46
And also here is a fun challenge for
4:49
you. Try changing the program to print
4:51
hello world for about 20 times instead
4:53
of 10. And also comment below how you
4:56
did it. If this video helped you
4:58
understand loops better, don't forget to
5:00
like, subscribe, and tap that bell icon
5:02
so you never miss another Python lesson.
5:04
Remember, every single line of code you
5:07
write takes you one step closer to
5:09
becoming a confident programmer. See you
5:12
in the next one and until then, keep
5:14
coding and keep saying hello world to