C_39 Do while loop in C with program | C Programming Tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the series of learning programming in c we have discussed for loop and while loop in c in detail in my previous videos now we are left with one loop that is do while loop so that loop i will be discussing in this video everything about do while loop the syntax of low while loop working of do while loop with the help of a flowchart as well as we will see uh the working of dual with the help of a program and we will also see some differences between while loop and dual right but before that just want to tell you one thing an academy is back with another exciting test series for gate aspirants who join the free special classes first build your concepts and then take the revised india gate 2021 test series this test consists of three levels first two levels would be containing 30 each each level will be containing 30 questions and to be sold in 90 minutes just to warm you up and get you ready for the grand finale where you will get 65 questions to be solved in 180 minutes this test has been curated and reviewed by the best faculties the top educators at any academy and the test has been designed as per the new gay 2021 pattern you can take this test freely and if you take this test live then all india ranking would be given to you after each test paper analysis will also be done by the top educators that will help you to identify your mistakes and improve accordingly so unlock the test using my code jkl10 and one more thing an academy combat for gate and esc is back with its fourth edition that would be live on 26th of january you can enroll for this combat freely you don't need to pay anything and use my code jkl10 to unlock this combat here you will compete with thousands of learners so take it live and compete with the best assess your gate 2021 preparation in just 65 minutes you will get a chance to solve challenging and the original gate questions created by the top educators at an academy if you take it live all india ranking would be given to you and according to that if your rank is good you can also win some exciting prizes you can see the detail over here so if you are interested you can go for it all the details all the links as well as the code jkl10 i'll put in the description box of this video you can go and check out so now let us discuss about do while loop it is almost same as while loop but we will see what is the difference between between while and do y see first of all as you know while loop and for loop those loop are entry controlled loop right and this is what exit control loop now what does this mean exit control loop i have already discussed whenever i i was discussing the in that video introduction to loops i'll put that video inside button you can check out there so this is exit control loop while we are exiting from the from the loop at that time condition would be checked right see the syntax of this do while loop then you will get it better first of all you will write the do this is the keyword after that in curly braces this is what body of the this do while loop so here we will write that statement some statements which you want to be executed within this loop right so this is what statement block right and after closing of this curly braces after that we will write y and here we will write some condition and after this we will put a semicolon this you need to take care in y when you write while condition we don't put semicolon right but here we put semicolon after writing the condition it's not compulsory that you have to write after this curly braces only you can write the while condition in this next line also that is also fine but this you need to take care you have to put semicolon after this otherwise it will give you syntax error right now the initialization would also be done because here we are seeing only the condition but i have told you three factors are there with with any loop initialization uh condition termination condition third one is increment or decrement or you can say update or modify expression so here we are seeing only condition right so what you can do you can also write something like this before this we do initialization before starting of this do while loop then do here we write some statements to be executed statement 1 statement 2 like this statement n here we write within this body of the loop we write that increment or decrement or you can say modify your update expression after that we do while we write what y condition and just terminate it you do something like this right or you can do this initialization within this body of the loop also that is also fine you can try it out right i'm just telling you first of all the general syntax of writing do while loop right so now as you can see what is the working of this two while loop first of all the statement block would be executed because we are not going to check any condition without checking the condition control will enter into this block whatever statements you are writing here that would be executed after that condition would be checked if the condition is true again it will enter into this loop the statement would be executed again condition would be checked right after doing some modify or after you know updating that variable after doing some incremental decrement again condition would be checked and if the condition is false then control will go out of this loop right so if you draw a flow chart how you can do first of all statements should be executed statement block right now after that what it will do modify your update or you can say some increment or decrement this would be according to the requirement of the program right suppose if you want to print number from 100 obviously increment if you want to print number from 100 to 1 then it would be a decrement right after that we will check condition if the condition is true there can be two cases true or false again control will go to here again the statement block statement will be executed again update or modify increment or decrement again condition would be checked this would be in loop if the condition is false that in that case out of this loop whatever condition you write here after the loop that would be executed right so this is what simple working of this do while loop i hope you you got the working of this two while loop so let us discuss it with the help of a program now now see after looking at this syntax and this flowchart what you can say about do i loop that the body of the dual loop will be executed at least once without checking any condition right in any case it would be executed at least once irrespective of the condition if the condition is false then also this will be executed at least once after that because it is not exit control loop we are not checking the condition while entering into this loop without any condition we are entering into this loop right so that would be executed at least once then we check while exiting from the loop we are checking the condition now the condition is false then it will not again enter the slow in this body of the loop it will exit but at least one it will execute right now let us see with the help of a program why i am saying this the body of this loop will be executed at least once what output you will get when you write a program see now see here i'm i'm taking a variable i right and here i'm initializing it with 0 now see in the body of the loop do control will enter into here because there is no condition here printf jenny so on the output screen jenny would be printed once now check the condition while i greater than zero means i zero zero is not greater than greater than zero so condition is false now it will not enter again it will go out of the loop so now it will print out of loop it will not print in the second line if you write here like something like this slash and then it will print into second line right otherwise it will print jenny out of loop right see let me write this with the help of while loop same program same i am initializing the psi with 0 now in while we are checking condition before entering into this loop while i greater than 0 is i greater than 0 no so it will not execute this body of the loop it will go out of this loop out of this loop whatever i have written out of loop so what output you will get here out of loop only here you will get jenny and out of loop so now we are getting the difference right that is why it is called entry control loop it is what exit control the loop here the conditions here whatever you will written you will write here within this body of the loop that would be executed at least once irrespective of the condition whether it's true or false right i hope you are getting my point now second difference is what here we write what semicolon after this while um statement here we are not writing any semicolon here if you write semicolon it will give you error here if you will not write semicolon then it will give you error right so when you will use this why do i loop when you want to execute these statements the body of the loop at least once means when you want to execute the body of the loop without checking the condition at least once then we use in those scenarios in those cases we use do while loop but if you want to test the condition first and after that you want the body of the loop would be executed then you will use either for loop or while loop according to your convenience right so now this is the difference between while and do while fine so now see here if i do i plus plus now what output you will get here tell me in the comment box in do i loop i am putting here i plus plus i is zero i'm printing jenny then how many times jenny would be printed whether it would be infinite loop or ah tell me it is finite loop then tell me how many times the journey would be printed right so this is now your assignment so now that's it for this video and i'll see you in the next video till then bye
Info
Channel: Jenny's lectures CS/IT NET&JRF
Views: 25,063
Rating: 4.9499307 out of 5
Keywords: data structure tutorials, operating system, data structure and algorithms, jayanti khatri lamba, jennys lectures, jenny data structures, jennys lectures DS, jenny lamba, jennys baby, jennys lectures baby, data structures, c programming tutorials, programming in c lectures, c programming jennys lectures, loops in c, do while loop in c programming, difference between while and do while loop in c, arrays in c programming, data types in c, gate cs lectures
Id: nohmBtIby_k
Channel Id: undefined
Length: 9min 59sec (599 seconds)
Published: Fri Jan 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.