30 - BREAK AND CONTINUE KEYWORDS - C PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome to our Channel so in the previous session we discussed it regarding the different in try to cut those statements so in then we have seen three iterative statements while loop for loop and dowhile so in Y and far loop the condition will be checked at the beginning itself and if the condition is true then only the control will enter into the body of the loop so in the in the case of doing first the control will enter into the body of the loop and then the condition will be checked so if the condition is true then the second iteration will be done or else it will come off from the loop so that is why at the beginning itself we are taking the condition that's why this pop up and why loop are called pretest loops and at the end so after executing the block of statements once at the end we are checking the condition in the divine soul Dubourg is called post-test loop so in this session let us have a look on break and continue statements break and continue statements break any pending new statements so here already we have seen this break statement in the switch statement so what are the key words break and continue both of the key words so a key word is an English words given by the compiler which is having a specific task so here also the break is a keyword which is having a specific task and continues a keyword which is having its its own task coming to this break so we have seen this break statement the importance of break statements in multi way selection statement that is a switch so whenever the control if you use this break statement immediately the control will come out from the loop so the rest of the iterations will be terminated so immediately after executing this break statement the control will come out from the loop and coming to this continue so this is also similar to the break statement so it is also given and here the continue means the particular iteration will discontinue statement has been written will be ignored and the control will start executing the next iterations so as I have said that iteration is a number of times the block of statements being executed so for example if we make a code which executes the block of stators ten times we call the mass ten iterations so here if we write this continue if the control executes this continue statement it skips the iteration but not the intent loop coming to this break it skips from the entire group so break continue so whenever the control exhibits this drag statement skip span blue let us continue it skipped from current iteration so in good Czech nation the continue statement has been redundant syntax the syntax is as it is a keyword just write the keyword break small letters and press the semicolon here syntax is also the continues a keyword with a lowercase letters so write the keyword placement semicolon so break means it comes the control come out from the loop continuous the control will come out from the current iteration in which iteration the bacteria has been written let us see the working of break and working of continued first coming to this break working how this brain works so we can write this break and continue statements in any iterative statements so we can include this break in for loop likewise we can include this break in while loop and we can include this break in doing my condition so we are will have to check the condition at the beginning itself then only we will enter into the loop so some statements without we are writing and if some condition so if this condition satisfies we are implementing this break so this bracket container statements will be used in integral statements see as initialization condition I'm Dixon why so these are the sim Nexus as we have seen in the previous sessions so coming to this value as it is called as a pretest pen 3-2 loop so the condition must be written in the beginning and the control will check the condition and the start of itself and if this condition is true that'll be the control will enter into the loop and these statements will be getting you get and if condition so here again we are reading the condition if this condition becomes true then if you later into the if block so we are writing this break statement so whenever the control comes into the break automatically the control will move out from the loop and it will execute the statement kicks so whatever statements written in the loop if the control introduced this break statement immediately the control will come out from the loop and the sequential execution will follows and here M so similarly do while here also if this condition is true we are ready to break so whenever the control comes to the break statement it automatically in the control when it comes out from the loop and it will execute situational attribution then who is the statements just later below the loop similarly here come to this for loop for initialization condition and updations of a loop variable we have written some statements and in that who have written this if conditional statement so if the condition is true the break statement will be executed and if this rate statement executes the kernel auto v 20 moves out from the for loop and it will include you statement X which is written just below the so if the condition is true or false even if the body condition if the condition is till to immediately of the control reaches the break statement the control will move off from the loop so even the condition is true if the front row introduce the break the femoral will come home from the move it doesn't introduce any more statements in the loop after executing this break statement so like this we can implement this break statement in different data into statements also in the multiple selection statement that is switch so hope you understood this working of break and let us have a look on iteration continuous continue statement working of continued let us look at working of continue and then we will see the example program for this blatant Canty so replace this break statement with a continued state continued so here also similar to the break discontinued segments will also be used in interactive statements so that means in while loop do well co-op for loop anywhere we can write this continue statement so wherever the control meets this continue that means well the control execute discontinued statement the control will keep the current iteration in which discontinued statement has made better so you know wherever this continues executed automatically it stiffs the remaining statements of my condition and immediately the Talco will move on to the condition check so if you write any more statements here so that is why it one more statement here so we are writing this statement by so now if the condition is true the control will enter into the block and here also if the condition is true continuum and after after this if block we are reading the statement while and whenever the control execute is continued the remaining statements of the loop will please keep and the control will move on to the next condition check so that means it skips the current iteration whether this continue statement has been theta similarly do both here also the continue wherever the continue is instituted all the remaining statements of the loop will be skipped and it will be moved in to move to the condition that means next iteration that means next round also if it is continue again it will go to the condition check all the remaining statements will be ignored so that means it doesn't comes out from the loop but it comes out from the iteration hope you understood is working of break and continue so this is a continue working continue working of continue so this break it continue statements can be used in interactive statements now let us handle become an example so that the small dots which you feel will be fade out if you have a little bit conclusion those confusions will be fade out if you see this example for break it continue let us write an example program so if I will write the program so they understood so this is an program to print the El natural numbers here first we are printing the I value initially the I value will be 1 because we have initialized in the photo is not equal to 5 minus plus so that first this condition will be checked so 1 is equal to is equal to through table that is false so obviously these block will be skipped and then we printed I so what will be printed now as I plus plus half be done so I will be down to 2 less than or equal to 5 again and I will do the follow because the statement is true the condition is true again now I is equal to 0 to 3 now I is equal to 2 2 is equal to is equal to 3 it Spanish toothpaste so it doesn't attend to this block so the Deaf ice the statement will be executed so we will be printed to next as we have seen this I will be incremented so that is 3 3 less than or equal to 5 3 less than or equal to 5 the condition is still true so again the control will end up include so here if I is equal is equal to 3 so they is equal to is equal to 3 so the condition is true so the control will enter into this if block so give statement ring immediately after dude in this break the control will come out from the so the output for this program is 1 & 2 because PL we use this break statement so immediately after the break statement even the condition is true 3 less than or equal to 5 it is no condition is - after executing the break statement the control immediately come out from the loop so it is executed now of the other suit if you replace here with continue see here here also the same statements I is equal to one so that one less than or equal to 5 I plus plus 1 is equal to is equal to 3 false so directly print is that means 1 next I press well so 2 2 less than or equal to 5 again the condition is true again so the control will enter into the room 2 is equal to is equal to 3 the condition place so it does not attack to the if you go print if I that means 2 now again 3 so we do not write a write plus plus 3 less than or equal to 5 3 is equal to is equal to 3 the condition is true so the dog will enter into this if condition here we have to continue so whenever we have written this continue once again it will check the condition so it skips the perfect iteration that means all the remaining statements will be ignored for the current iteration so once again it moves on to the condition so I press place has been executed so that is equal to 4 4 less than or equal to 5 condition is true for the super this is equal to 3 so here it is false so the control will never enter into this is block print F I so I is equal to 4 conditions implemented look very cool implemented so now I is equal to 5 5 decimal for default again the test is to the controller will enter into the block so 5 is equal is equal to 3 the condition fails it does not enter into the clock again the printf statements in the executed and it will 3 5 and task these I plus plus is increment and the loop is implemented I now becomes the 6 6 less than or equal to Phi the condition fails so then the control moves out from the loop so the output for this program the same program huge fan of for break statement this way replacing the break we can't now probably one two four five because in the oppression in the condition I is equal to is equal to three we are writing the practical that means we have we are just we are keeping this statements when I is equal to is equal to three that means the continue where wherever the a continuous statement is executed the all the remaining statements of the current attraction will be ignored and continue with the next iteration so that's why the continue we'll skip the impression and break we'll skip the loop entire loop so this is an example so hope you understood this break and continue statements and if you have any more doubts regarding this break and continue statements please post your doubts in the comment session so that I will flag for your doubts and then let us stop here in the next session let us have a look on arrays and if you like my videos do subscribe to my channel and share my videos with your friends thank you very much for supporting me and my channel thank you
Info
Channel: Sundeep Saradhi Kanthety
Views: 48,701
Rating: 4.8990426 out of 5
Keywords: Computer, Computer programming, cp, c programming, c language, sundeep, saradhi, kanthety, break, continue, break example, continue example, working of break, working of continue, break program, continue progam, break in loops, continue in loops, while loop, for loop, do while loop, iterations, iterative statemens, break & continue, keywords, break keyword, continue keyword
Id: cj7HKjUGWhU
Channel Id: undefined
Length: 19min 58sec (1198 seconds)
Published: Tue Sep 12 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.