Loops & Control Statements in python
Loops :
In python loops are use when you have the block of code which you want to repeat it fixed number of times.
Now you might think that ....what would be that thing that which part of code you want to repeat again & again🤔. So let me give you some example :
* To write the multiplication table of 5 till 10th place will become quite tedious job for you where you keep on printing 5 with every number from 1,2,... till 10. Instead we just put it in the loop; now you will think how to do that don't worry my dear readers because i'm here.
*Basically to fill our purpose we will see 2 loop's :
(i) While :
In python while loop is used to execute a block of statement repeatedly until a given condition is satisfied & when the condition is satisfied then loop stop's & the statement / code below / under the loop gets executed.
*Syntax of while loop :
while expression :
statement_1
*Example :
Did you stuck while applying the while loop?...Do you need a help?...comment below or check this video which will help you to solve your doubt.
(ii) for :
A for loop is used for iterating over sequence i.e either a list, dictionary, set, string.
The for loop does not required variable to set earlier.
Basically for loop will be in 2 parts ....not exactly i'll say but its just my opinion.
a.) for in :
In this the loop will be iterate from the particular String, List, Dictionary etc.
*Example :
b.) for range :
In this the loop will iterate from the range that we given in.
*Example :
Hey guy's this video is specially for you in which all the topic regarding the For loop will be cleared.
Control Statements :
Loop's control statements change execution from the normal sequence. When execution leaves a scope, all automatic objects that were created in that scope will be destroyed.
In python there are following control statement:
(i)Continue statement(ii)Break Statement(ii)Pass Statement
(i) Continue Statement :
It returns the control to the beginning of the loop.
*Example :
(iii) Pass Statement :
Basically it will skip the value.
*Example :
Thank you guys... For visiting our website. Do you want to keep learning regarding topic such as Data Science, Machine Learning or Deep Learning with real life projects please do support us by just putting a quick comment 'yes' below.
No comments:
No Spamming and No Offensive Language