Hello guys, my name is Joel Mukanya
am a CEO and Founder at JT Devs
for today video, we going to look at some examples that we going to use uh in python
okay
those examples will be base on loops
let define a loop. A loop base actually allows us to repeat something
or a block of statement
yeah that will be a loop
so let say for example you want to know
how many times do you have to display
numbers from 1 to 10 then you will need a loop
so you just have to type in on statement then
you need to increment your counter then
it will display from those lowest numbers to the highest number
or from the highest number to the lowest numbers
it will depend on your logic. Let start with the
while loop. A while loop most of the time we use it
when we actually do not know where to stop
or when to stop then it kind of a process
then if something your program somewhere
you are dealing with a process of knowing things
while you're doing something then you can use
while loop
First, let create a counter. A counter will be
anything, any variable that you wanna use
in my case am going to use cnt equals to zero
then we say while cnt is less than seven
why? because we want to display numbers from zero to six
then we say cnt. Then after that, we have to increment
our counter
then let increment it. Then we going to say cnt += 1
then we have one to six
What is a range()? A range allows us to generate
some numbers from start to end. So we going to see it in action using a for loop
a for loop allows us to know or to generate numbers
from lowest numbers to highest numbers
or from highest numbers to lowest numbers
then it also allows us to repeat something
but with a for loop, we already know where we should end our loop
i, it will be your counter. Then we will say range(10)
let say for instance, if we want to display from 1