PYTHON PROGRAMMING CLASS (THE BASICS) || DAY 3 - PYTHON LOOPING STRUCTURES(While Loops) | WEEK 3

in Steem4Nigeria2 years ago

python class banner day 3 week 3.PNG


Good day everyone!
Hope you're doing great!! Welcome back to my Python programming class. Today is the third day of the Python Programming class week 3. If you have followed my week 1 & 2 till the end, you must have acquired some basic Python programming skills that can help you start your programming career. However, if you did not follow my week 1 & 2 classes, please visit my blog now @anyiglobal to see all my week 1 & 2 classes.

I brought out this idea of teaching python on steemit because of the need for python programming skills in the world of technology today. This is the new trend in tech now because python can be used for various purposes in many applications ranging from web development, automation, artificial intelligence, software testing to many others. I decided to start this programming class on steemit communities because the communities comprise mainly of people who are still eager to learn new skills. Developers and non-developers alike can use this python.

This is my first time of posting in this community, and I believe this community will treat me right!

Note: The English language used in this class is literally understandable by a layman. So let's begin...


PYTHON LOOPING STRUCTURES

As we have defined in our previous class, let's quickly recap what Loop is and what Looping structures is too.

According to English dictionary;

Loop is a programmed sequence of instructions that is repeated until a particular condition is satisfied.

In Python programming language, loop structures are used to iterate certain range of numbers or sequence until a certain condition is met. Looping structures are used in application programs as at when required to execute a set of statements iteratively for a predetermined number of times until a certain condition is met. To achieve this, we make use of "For loops" and "While loops". We will discuss While loops in this class with examples.

NB: But before we proceed, let me just make it clear to my students that this class will not be long as our previous classes, please bear with us!


PYTHON WHILE LOOPS

While Loops is also a looping structures which tests a condition first before the group of statements is executed and which repeatedly executes until a predetermined condition is satisfied or True. If you're still confused about what I just explained, don't worry we will illustrate that with example later in this class. The While loops requires an important variable before hand to be ready. The important variable is defined as an indexing variables like x, i, e.t.c. that holds our elements during the iteration.


While loop Syntax:
While expression:
  statement(s)

For Example,
Let's print 8 numbers to the screen by iterating through the sequence using the while loop.

i = 1
while i <= 8:
  print(i)
  i++

Output

Here "i" is a variable that holds each element during the iteration until the condition is True.

python while loop.PNG
Python while loop

From the above screenshot, we all can see that the iteration stopped as soon as the condition is satisfied. Please make sure you practice along with me so that you won't be loss anywhere.

NB: Copy the code in the example above and try it out in your text editor.


THE BREAK STATEMENT
The break keyword functions as the same as that of For loop. It is used to break out of a loop when a specified element in a sequence is met according to instruction. Let's look at some examples of what we have been saying here since.

For Example,
Let's break out of the loop when i is equal to 5, i.e. i == 5:

i = 1
while i <= 10:
  print(i)
  if i == 5:
    break
  i += 1

Output
1
2
3
4
5

python while loops break statement.PNG
While loop break statement

Looking at the screenshot above, we can observe that the iterations stopped as soon as the element specified in the sequence is met. Note that you can also use while loop to iterate elements in other sequence like lists, tuples, dictionaries, e.t.c. Use this material to learn more about Python while loops.


THE CONTINUE STATEMENT
Continue statement in a literal manner is more like telling someone to skip a certain number while counting a sequence of given numbers. In Python programming language, the continue statement is used to skip a specified element in the sequence. However, the continue statement will skip the current iteration and continue with the next. Let's see an example below to have a better understanding.

For Example,
Let's use continue statement to skip an element in the sequence if the iteration encounters number 6, i.e. when i == 6.

i = 1
while i <= 10:
  i += 1
  if i == 6:
    continue
  print(i)

Output
1
2
3
4
5
7
8
9
10

python while loop continue statement.PNG
While loop continue statement

As we can see from our code above, the number 6 is skipped as the iteration encounters it, this is because we specified in the if statement that the iteration should continue if it encounters a number 6 in the sequence. Use this material to learn more about Python while loops.

NB: Copy the code and try it out in your text editor.


Conclusion

It is pertinent to make use of conditional and looping statements in our program because that is the only way we can make decisions in our program. In this class we have covered while loops, the break statement, and the continue statement. Please as a student, do well to practice along with the teacher, and also make sure you read other materials from other websites to have an in-depth understanding of what I teach you here. In our next class, we will look at "Python Functions". Thanks for being part of this class, I appreciate your coming!!



This is the end of this particular class. I believe that if you followed this class till the end, you must have grabbed one or more information from the class. Please make sure to practice along with your laptop and text editor to grab every bit of the information passed.

Please do well to follow this blog, and also don't forget to resteem this post so that it can reach larger number of steemians who wants to learn this skill.


Am glad you participated in this class! I believe you have learnt something new today.

I am @anyiglobal, a Computer Scientist, Software Engineer and a Blogger!



THANKS TO THE COMMUNITY ADMINS FOR THE SMOOTH RUNNING OF THIS COMMUNITY
Cc: @steem4nigeria @reminiscence01 @ngoenyi

Sort:  

Sir you are not in any club right now, so please do not use #club5050 tag here. Or power up some of your steem to use this tag.

IMG_20220716_112919.jpg

How can I start from the basic do programming, am seeing a whole lot of people going in to programming. And as such it interest me, but I have limited knowledge of computer, I just know the basics

 2 years ago 

Congratulations, your post has been supported by @steem4nigeria. This is the official community account of Nigerians on Steemit. You can reach us here on our community account.

Manual Curator : @Reminiscence01

Subscribe and Join Steem4Nigeria Telegram
Discord Facebook Twitter

@reminiscence01 @ngoenyi - As Admins of Steem4Nigeria why are you not checking posts properly?

This post is using the #club5050 tag but it not qualified to, and yet you still voted on it.

Please check all posts in your community are checked and commented correctly and properly otherwise it will count badly against your community.

 2 years ago 

Thanks a lot for this advice sir. We will surely check publications properly going forward. This is just an overnight. But I personally apologize for it. It will not happen again.

@anyiglobal, it is very wrong to use any of the club tags when you are not qualified. Please, before you use any of the club tags, ensure that you are in them. Kindly edit this post and remove the club5050 you have used since you have not powered up half of your earnings in the last one month.

Hi, the user anyiglobal just made (in 1 month(s)):

  • CASH OUTS: 130.001 STEEM
  • POWER UPs: 107.226 STEEM

CLUB5050: ❌ NO elegible. You should power up 22.775 STEEM

I just used cotify to check your club status and the above is the result. It's either you power up immediately to join club5050 or you remove the tag. I will be looking forward to seeing the action you have taken to this effect. Thanks.

Cc: @steemcurator01

Thanks very much for the information! I am seriously working towards powering up any moment from now!

 2 years ago 

That is good. But please, do not use the club tag since you not there yet

I just updated my club status, check again

 2 years ago 

Thanks for joining club5050.

Hi, the user anyiglobal just made (in 1 month(s)):

  • CASH OUTS: 130.001 STEEM
  • POWER UPs: 133.226 STEEM

CLUB5050: ✅ Elegible. You should power up 0.000 STEEM

Thanks for the review! I am sorry for any inconveniences this might have caused!
So won't it be curated again?

I apologise for this. We will enhance the measures for curation in our community. Thank you.

I'm impressed with your lessons. As a python programmer, I can tell how easy and educating your lessons are. I hope users can engage and take good advantage of this opportunity to learn python. You are doing great.

Thanks very much sir for the acknowledgement! I am out on this Blockchain to bring quality contents to the users as far as the support is massive!

Loading...

Coin Marketplace

STEEM 0.19
TRX 0.17
JST 0.031
BTC 82195.61
ETH 3201.57
USDT 1.00
SBD 2.81