ITERATIVE CONTROL STATEMENTS - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in previous sessions so we're discussing about the different control structures and then control statements in a Python so among that we have seen three categories what is sequential control statements decision control statements and iterative control statements so among these three we have already seen from the first two things that is a sequential control flow and the decision of those statements so in this session let us have a look on the third one that is iterative control statements see before going to the iterator got on sale - first we have to know would I mean which statements we call it as an a try to control statements so whenever a block of statements are used to execute repeatedly first number of times that we call it as an iterative statements so for each time of execution we call it as an iteration so for example if some set of statements are need to be executed ten times so that we call it as a ten iterations so every time we call it as an interaction so ten iterations and then so people are going to that we have to take that out the three things one is loop variable initialization second one condition for termination third one foundation of loopy so I have to take about these three things so before starting the look we have to initialize one variable and the second one is at particular time the loop should be terminated that makes a path for getting the finite number of iterations so if you fail you to write this condition it will go to the infinite loop so that loop will not terminate so it will continuously the number of iterations will be increased next application of variable loop variable so we need to for every iteration we need to update this loop so great upon this room where you have provides the condition right so these the things we have to take care about these in introduced statements so there are two types of iterative statements one is why you so this is introduced statement will call it as and oops right while loop and for loop so you see language there is another loop there is a do-while loop here there is no chance of third one only two categories are there what is wild loop and fun so let us see one by one see every below so as discussed in the previous session so here the lot of statements will not be represented in between these curly braces and for every header if you include the column as a suffix automatically the indentation will be applied and the person will you four spaces on the left side and the control will starts then the Cassandra starts from fifth space that implies I mean this arrived way in place these are the some set of statements which are represented for this particular header that had a maybe if if-else or or why not doing anything right so all the statements which are represented by using this indentation will represent a drop off statement right so instead of using these curly braces we will use this indentation amendment right now let us see the syntax for this syntax for while loop by condition or on underneath even have to write from here statement one statement tube and so so this may be a single statement or multiple statements so this arrangement so we can see this event represents the block of Y blue so the things until this condition becomes false all these set of statements which are Iying will be exhibited repeatedly so we let me have true after the condition fails automatically the curtain is about sunroof the frames the next just friend after prevail should be aligned from here itself see listen so all these are in Rick's will comes on them not of value and whatever the statement we are writing which is equal for this a while alignment that will be the sequential execution that means this will be exhibited after the condition becomes false right so this is a simple syntax for value so let us see the example see this is a comment in Python bring in natural numbers right now for this first we have to read the N value so n is equal to int of input enter and value so n will be having fun value now initialize the loop variable let it be n is equal to 0 this is a loop variable initialization next condition for termination next occasion know this is a loop variable by I less than or equal to n so this is the condition where you have to stop what we have to do think the I I is equal to n plus 1 so okay thank you and not food see this tape it implies so this is the first one loop variable initialization this one is the condition so then we have to stop this one is the updation right so here so in Python then there is a long increment and decrement operators so we have to replace those increment and decrement operators by using this augmented and segment simply we can use this assignment operator than three operator so I is equal to n plus 1 we have to write a plan like this so we we should not find a 5s mess because this is no increment and decrement operators in Python right so see first M value so let it be any value is equal to 5 now I will equal to 0 is not equal to 5 0 less than or equal to 5 - 3 I so that means 0 will be printed at a super high class 1 so I is equal to 1 n is equal to 5 bar is not equal to 5 print ie so what will be printed and is equal to 5 I is equal to I plus 1 so to fool has hands equal to 5 - 2 will be printed they will be printed for me be printed another guy is equal to 5 so here we have written 5 less than or equal to 5 this is also true for it will be printed again I is equal to I plus 1 now I is equal to 6 so 6 now we are required to find here the condition false so automatically the result will be 0 2 and right from 0 starting from 0 1 2 3 4 & 5 so if you initialize this 0 with 1 so here the display will be from 1 to 5 so hope your result disability so why look so easy for you may hamper follows all these paintings right no there's more than second one that is faboo from so here also we have to initialize a variable condition and updation but in a different manner so here we will write for I in sequence so these sequence can be a tuple or exist or dictionary all it means so this sequence can be anything so here it can be a list tuple dictionary or range so I will be followed with all the values of in this given range or in given dictionary or a given tuple or a given list so all these four of the sequential data types so that means these are the data types which will accept the sequence of elements with the different data terms right so let us see this range so afterwards in the coming topics we will move for these three lists to blend dictionary now let us stick on to this range see I heal range now let us see the syntax for this range so range start stop step face so there are three arteries involved in this range function so here we have to give the start value from where I will be included next we have to give the stop where you where where I should be ended this is the end value start value and value and this step size is the difference between the first iteration element in the next iteration element so this is nothing but our updation right so this is a loop variable we are initializing this is the initialization so start so starting value stop where to stop this is the condition itself here it something is the condition so this stop element is the last element and step size is difference between the first equation X second iteration that means updation and this fact if you mentioned this start that is well and good and if you are not mentioning this start the starting will be always 0 by default that means I value in range function always starts from 0 and this step size here also is an optional thing this should be mentioned by the programmer if programmer doesn't specify the step size the default value is 1 the default value is 1 that means just an increment so if the I value in the first iteration is 0 then in the immediate next iteration the I value will be 1 in the next iteration either will be 2 that means the difference will be 1 so if this step size is not mentioned by the program as far must be mentioned by the programmer itself so if the programmer mentioned and the last element will be L minus 1 right so if n is the last element I mean and is a stock element in the event the value is n minus 1 will be the last statement so it should if you do not include this value and value so that means simply a range of 0 comma and comma 1 this implies 0 to n minus 1 with annuity difference right from 0 1 2 3 4 and so on and minus 1 this function or else or else simply we can mention all the way in value range of yen little place 0 2 here minus 1 with unit difference because here we are not mentioning the stock we are not measuring the step size so here whatever the bench we are mentioning is the last size so if there is only one argument that argument is automatically the stop element that is the end admit so n element it whenever it is yell the last segment will be a minus 1 so I will create records on to 0 here there is no stamp so automatically by default if you take a 0 and here the half step size so order ideally it will take it as 1 as a difference now let us see hope you understood this range let's see so range yeah are simply range file sorry yes right this index first and then we will move on to the program I need in sequence column automatically the indentation will be applied statement 1 statement 2 and so on so this is a simple syntax for fun now let us see an example by using sequence as a range so we return we need not addition is this I before starting the fumble because loop variable initialization condition of notation everything we are writing by in the range function its range of M so sorry range of file colon print I so here what if 100 is there so that argument is in a little bit so my D Phi DT will be high value will be 0 and the last element will be 4 so first element and this is the last element and the difference is 1 because there is no matching of step size so the output for this one is 0 1 2 3 4 that's it because we are giving files of for of the 4 it will be printed now if we mentioned here the step size from g-41 to find that in price the first one first argument will automatically consider it as a start element and financing and they'll be so by default the last element step size is 1 so now prefer this one is I will start from 1 so starting element 1 right if you have one function here 1 if we take it as a 0 so 1 2 3 & 4 right next if you mention here to the face start is one last element is 5 minus 1 4 and the difference is 2 now for this one is first start money to difference 3 to difference for you so fine is not included because of our step in this 500 well look for is the last last angle so what anything is the output for this n simply if you right here start from 5 0 minus 1 right this is simple output if I start from 5 - 4 they are giving so 4 3 2 1 okay n 0 0 also will be printed next so if you use here - - to automatically fun 3 this is the output for this thing so we can write ascending in the ascending order but it is anymore so this implies the updation this implies the condition that means the range is the ultimate condition this is the initialization right stop stop and different so this is a simple example huh using this problem it's a very simple man comparative oversea language so you see language we have to use three terms in the problem first initialization condition and updation and then a lot of statements so here yes we can make sure all these three things in a single function there is a range with the three arguments first one is starting element in the last last element again struggle with and then with a difference that means a step size so this is a very simple thing so these two comes in then our iterative control statements so hope you understood this simple iterative statements which we really understood my videos like my videos and if you are having any doubts regarding this enter into control statements feel free to post your thoughts in the comment section so that I will definitely try to can fit all your notes and share your sharing sessions with your friends and don't forget to subscribe to our Channel so thanks for listening and watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 39,541
Rating: 4.9060664 out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, HIGH-LEVEL, LANGUAGE, PORTABLE, FEATURES, APPLICATIONS, INSTALLATION, INTERPRETER, PYTHON SHELL, PYTHON SCRIPT, INTRODUCTION, BEGINNERS, GUI, GAMING, PYTHON 3.7.0, CASE SENSITIVE, SIMPLE, PYTHON BASICS, decision control, if else, nested if, if elif, false block, test expression, control structures, WHILE, LOOPS, ITERATIVE STATEMENTS, RANGE, PRETEST LOOPS, START, STOP, STEP SIZE, INTENDATION, ITERATIONS, LOOP VARIABLE, FOR
Id: fD_NVy85Xxw
Channel Id: undefined
Length: 21min 42sec (1302 seconds)
Published: Mon Aug 06 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.