do-while Loop

Поділитися
Вставка
  • Опубліковано 19 чер 2018
  • C Programming & Data Structures: do-while loop in C programming.
    Topics discussed:
    1) Difference between while and do-while loop,
    2) When should I prefer do-while over while?
    C Programming Lectures: goo.gl/7Eh2SS
    Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
    Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
    Contribute: www.nesoacademy.org/donate
    Memberships: bit.ly/2U7YSPI
    Books: www.nesoacademy.org/recommende...
    Website ► www.nesoacademy.org/
    Forum ► forum.nesoacademy.org/
    Facebook ► goo.gl/Nt0PmB
    Twitter ► / nesoacademy
    Music:
    Axol x Alex Skrindo - You [NCS Release]
    #CProgrammingByNeso #CProgramming #dowhileLoop

КОМЕНТАРІ • 173

  • @sidla6989
    @sidla6989 4 роки тому +209

    2:55 , i like how you noted that you need to put the semicolon after the "do...while" function while you did not use your own advice

  • @siulichatterjee3652
    @siulichatterjee3652 2 роки тому +80

    Whenever he says "right?", I fear that in the very next moment he'll say ," wrong! !"😄😄

  • @aishwarya8253
    @aishwarya8253 4 роки тому +61

    Really ur explanation is great sir
    Even the one who do not know the c -lang by listening to this I’m sure that they’ll understand C lang clearly .
    Tq sir.......

  • @hinataaaaaaaa
    @hinataaaaaaaa 5 місяців тому +3

    Minutes of struggle solved in seconds

  • @S7VENFILM
    @S7VENFILM 4 роки тому +4

    Watching you grow. Thanks for sharing

  • @muhammadfauzanazima3807
    @muhammadfauzanazima3807 3 роки тому +5

    What fonts did you use in this tutorial? very interesting, I want to use it too.

  • @ksofficerofficer7858
    @ksofficerofficer7858 20 днів тому

    Every time I watch your teaching videos I'm getting better, Thank you so much

  • @kapkoder4009
    @kapkoder4009 3 роки тому +2

    Thanks for the explanation, now I understand

  • @ahmed6569180
    @ahmed6569180 4 роки тому +8

    thank you for ur amazing explanation.
    a small note: there is a missing ';' at the last do-while example you entere.

  • @ratchetbear3777
    @ratchetbear3777 2 роки тому +1

    Information was clear and concise.
    Thanks heaps for your efforts :)

  • @kennardsugirotok7374
    @kennardsugirotok7374 2 роки тому +2

    You are a very great teacher!

  • @saritasingh3713
    @saritasingh3713 3 роки тому +2

    Thank you sir. All my doubts are cleared

  • @mdamdadulislam7669
    @mdamdadulislam7669 3 роки тому +1

    I love this explanation.

  • @amberarts7356
    @amberarts7356 3 роки тому +1

    Thank you so much this was really helpful

  • @srta.carlota696
    @srta.carlota696 3 роки тому +1

    Thanks! It was a fast and simple explanation to understand. Nice video ^_^

  • @iqmal3910
    @iqmal3910 2 роки тому +1

    Excellent explanation sir VERY HELPFUL VIDEO

  • @belayfekadu
    @belayfekadu Рік тому +2

    what happen if we put semi colon in after while loop

  • @baohuariley5740
    @baohuariley5740 Місяць тому

    thank you so much. Now I understand difference between while and do while loop

  • @MarcGyverIt
    @MarcGyverIt 3 роки тому +2

    Your explanations are the best out there. If you have a paid course, I will sign up for it.

  • @672_tejasdesai3
    @672_tejasdesai3 3 роки тому +1

    sir your explaination is very nice, thank you sir :)

  • @celestinefrancis8401
    @celestinefrancis8401 Рік тому +1

    really extraordinary

  • @amandeepsinghdhillon143
    @amandeepsinghdhillon143 Рік тому +1

    My 2 hours work you solved in 2-3 minutes sir I am sure that your channel will be sure in top 10 ❤

  • @njabznmasikane359
    @njabznmasikane359 Місяць тому

    Thanks so much!

  • @TheoTime-bk9fk
    @TheoTime-bk9fk 7 місяців тому +1

    im learning c++ thanks a lot

  • @AzharAli-cr2vj
    @AzharAli-cr2vj 4 роки тому +1

    great instructor

  • @naveedsab1352
    @naveedsab1352 6 місяців тому +1

    For (int I=o;i

  • @miroslavblagoev5887
    @miroslavblagoev5887 Рік тому +4

    Thank you for the video, I just want to sat that - this code also works, uses while instead of do-while, and gives same output as your do-while loop with the same with even fewer lines.
    int n;
    while(n != 0){
    printf("Enter an integer
    ")
    scanf("%d",&n);
    }

    • @zaugitude
      @zaugitude Рік тому

      Yes, I tested this and it works.
      Here is the interesting thing, in the following code, the initial printf statement prints n with a value of 32764 to 32767 ( I only ran it a few times). If I comment out the while construct the printf statement then gives n a value of zero. Does the compiler see that it needs a non-zero value to make the while loop valid or what?
      int n;
      printf("n = %d
      ", n);
      while(n != 0){
      printf("Enter an integer
      ");
      scanf("%d", &n);
      }

    • @miroslavblagoev5887
      @miroslavblagoev5887 Рік тому

      ​@@zaugitude in C, Static variables (file scope and function static) are initialized to zero, but non-static variables (local variables) are indeterminate. Reading them prior to assigning a value results in undefined behavior. For example, if the above is in main, n start with 0, but if you have a function, and there you use this code, you will get unpredicted values. Also note that if the value in the brackets is not true, the code below will not execute. :)

  • @dattareddy6170
    @dattareddy6170 2 роки тому +1

    I want to know what compiler you are using in your lectures

  • @pakistancricket245
    @pakistancricket245 3 роки тому +1

    It was really helpful for me sir ❣️❣️❣️

  • @constantinkamgo6742
    @constantinkamgo6742 3 роки тому +4

    good content ;deep and well structured.

  • @santhoshjd2673
    @santhoshjd2673 3 роки тому

    Thank you 😊

  • @Pritamdas-bg7fp
    @Pritamdas-bg7fp 6 років тому +4

    neso academy is the best

  • @compangit1524
    @compangit1524 Рік тому +5

    Comments for myself: normal while loop is the while-do loop. Then, we have another loop which is called the do-while loop. do-while loop is used when we want to execute the body of the loop at least ONCE.

  • @avunooritagore6089
    @avunooritagore6089 5 років тому +9

    Sir.. I have a doubt in Second program both while and do-while is giving same output but you said if we won't place semicolon in do-while it should give an error but it is not happening here why?

    • @gp_sec
      @gp_sec 5 років тому +1

      He didn't run the 2nd program...

  • @nehagupta3668
    @nehagupta3668 2 роки тому +4

    Sir 🗣️a small note: there is a missing 👉';' at the last do-while example you entere.✍️

  • @UruzStrong
    @UruzStrong 4 роки тому +11

    What a fantastic tutorial, I struggled with this for a long time before seeing your video. Thank you

  • @A_A-qe3gx
    @A_A-qe3gx 4 роки тому +26

    Thank you sir for this video it's really good!!!

  • @asif7240
    @asif7240 Рік тому

    thanks!

  • @goldenG978
    @goldenG978 2 роки тому +3

    amazing, short and accurate!!!

  • @shauryasaxena5263
    @shauryasaxena5263 3 роки тому

    Tq very much sir and your method is very easy

  • @MdKhadeerPasha-wf6lk
    @MdKhadeerPasha-wf6lk 3 роки тому +1

    Sir in example of do and while u not putted semicolon in do while loop

  • @saptadeepghosh668
    @saptadeepghosh668 4 місяці тому

    For the while loop just initialize the n value with 1 before the loop starts , so it enters the loop as i>0.
    And you also don't need to take input before the while loop.

  • @mousaismail8757
    @mousaismail8757 2 роки тому

    I like this method of teaching

  • @shaheersheri1
    @shaheersheri1 3 роки тому +2

    Nice share keep it up

  • @anushabaskar
    @anushabaskar 3 роки тому +1

    U told that in do while loop exactly in while statement it should be ended with semicolon right??

  • @navkaransinghbrar4380
    @navkaransinghbrar4380 6 років тому +5

    Thats it ....I hoped u will post Programming videos.....I will watch whole of them but keep posting ....and also on java and C++

  • @humaarif437
    @humaarif437 4 роки тому +1

    what's the meaning of semicolon at the end of do while loop please dry run this loop

  • @AK--vc9wd
    @AK--vc9wd 3 роки тому +2

    I will learn full C from neso academy.

  • @francisjaranilla3335
    @francisjaranilla3335 Рік тому +2

    Hello Sir! How about you make a video about turning for loop into do while loop.. It will be very helpful. Thank you!

  • @true4189
    @true4189 3 роки тому

    Thank u

  • @ujjvalw2684
    @ujjvalw2684 6 років тому

    Awesome

  • @shubhamtiwari1190
    @shubhamtiwari1190 2 роки тому +1

    Sir aap jo next example diye the usme while loop k baad semicolon nhi lagye he

  • @Rajveer-yr5bp
    @Rajveer-yr5bp 2 роки тому

    Thnx sir

  • @budigesrivishnugoud6882
    @budigesrivishnugoud6882 3 роки тому +1

    🤔doesn't got any error for not using semicolon in do while???

  • @jimmymesa
    @jimmymesa 5 років тому +6

    Putting a semicolon at the end is probably necessary for the compiler to parse the source code properly.

  • @JustinVarghese
    @JustinVarghese 5 років тому

    great

  • @madhura9510
    @madhura9510 3 роки тому

    Sir plz make vdo on difference between definition and declaration of variables in c

  • @BTMINSiddhiChobe
    @BTMINSiddhiChobe 3 роки тому +5

    On 3:55, the program of do-while , there should be a semicolon after while

  • @vilanv-a6296
    @vilanv-a6296 3 роки тому +1

    so its literally another syntax to add an if statement in a loop?

  • @ilayda3046
    @ilayda3046 3 роки тому

    int b=0;
    int c=9;
    do {
    if(c

  • @md.mominulislam4189
    @md.mominulislam4189 4 роки тому

    Can i solve the same problem with for loop?

  • @heypikachu276
    @heypikachu276 2 роки тому +1

    Isn't this still classified as a while loop? I honestly have no idea because I use LUA and haven't learned C fully, but thought not "While true do," it's still a while loop, correct?

  • @ergoproxy3032
    @ergoproxy3032 Рік тому +1

    i like the explanation but when i removed the first printf and scanf from while loop it still works perfectly fine and as we want like this, therefore i still dont get the difference:
    #include
    int main()
    {
    int n;
    while(n!=0)
    {
    printf("enter integer");
    scanf("%d", &n);
    }
    printf("staaaaghp");
    return 0;
    }

    • @UttamKumar-dp9dp
      @UttamKumar-dp9dp Рік тому

      Where are you writing the code?
      I'm using replit and this code is not working

  • @AakashYadav-ch9un
    @AakashYadav-ch9un 3 роки тому +2

    Instead of that printf and scanf function we can just simply initialise n=1 in while loop

  • @zaidansari3595
    @zaidansari3595 Місяць тому +1

    Thnx ...very helpful ;_;

  • @asdjkk1297
    @asdjkk1297 2 роки тому +1

    4:00 look at the while program . You are not terminating the scanf function

  • @peravarapulalitha2105
    @peravarapulalitha2105 3 роки тому

    It's good 👍

  • @deepakj3727
    @deepakj3727 5 років тому +28

    4.10 you missed the semicolon in do while loop's side

    • @sitanshuravi3328
      @sitanshuravi3328 4 роки тому

      It is because he too didn't has used do- while much

    • @saulaur
      @saulaur 4 роки тому

      I think it is @2:42 :-)

  • @vaibhavgurav6291
    @vaibhavgurav6291 2 роки тому +1

    Thank you i understand but second example your missing semicolon sir but sir thank you giving explanation.

  • @diyandassembling2907
    @diyandassembling2907 3 роки тому

    Interesting.

  • @navalkishore6559
    @navalkishore6559 4 роки тому

    int n;
    printf("enter an integer");
    scanf("%d",n);
    while(n=0)
    {
    printf("enter an integer");
    scanf("%d",n);
    }
    printf("you are out of loop");
    when i use this code then and entered 0 then i got message "you are out of loop".
    and not when [while(n!=0)]

  • @lakshmanreddy1148
    @lakshmanreddy1148 3 роки тому

    Super

  • @shiv_crypto_
    @shiv_crypto_ 4 місяці тому

    I guess we can do same thing with both the loops as you said about that redundancy i wrote the code without seeing the answer if i am wrong in my code please correct me but its giving output that is required
    //C code using loop to stop user when she/he enters ) as input
    #include
    int main() {
    int i = 2;
    while(i!=0)
    {
    printf("Enter the number you want :
    ");
    scanf("%d",&i);
    }
    printf("You entred wrong digit :
    ");

    int j = 5;
    do{
    printf("Enter the number rather than 0 only
    ");
    scanf("%d",&j);
    }
    while(j!=0);
    printf("You entered worng value
    ");
    return 0;
    }

  • @sohailsohail9164
    @sohailsohail9164 2 роки тому

    2:41 displayed do while loop program no semi coloum

  • @upscallmydream
    @upscallmydream 2 роки тому

    Sir at the end you tell me the output will be the same because both the programs does same task.. but when u studied me difference between them. We used same task. But output was different.. in while loop no output but in do while loop output=0

  • @sathvikswaminathan7933
    @sathvikswaminathan7933 4 роки тому

    We can just initialize n to some non 0 value and use the while loop.

  • @ritikshrivastava9442
    @ritikshrivastava9442 3 роки тому +1

    If somebody wants to know how to write the same program using for loop
    int main()
    {
    for (int i; i != 0;)
    {
    printf("enter an integer ");
    scanf("%d",&i);
    }
    printf("you're out of loop");
    return 0;
    }

    • @brunobiega
      @brunobiega Рік тому

      what does the ,,&" sign before variable ,,i" mian?

  • @regular4993
    @regular4993 Рік тому

    It can also be n>0 ryt?

  • @Justin-yk1jk
    @Justin-yk1jk 4 роки тому

    do nested loop in C language please

  • @timwalt9190
    @timwalt9190 4 роки тому

    you are smart

  • @harishkumar-gg6nt
    @harishkumar-gg6nt 3 роки тому

    why your codes are not working in online complier

  • @shivangishukla3312
    @shivangishukla3312 2 роки тому

    4:01 why you didn't put ; on do while loop

  • @samararora2420
    @samararora2420 2 роки тому

    You didn't write semi colon after while in the program of do while when showing the program

  • @varishamalik9726
    @varishamalik9726 Рік тому

    Sir you didn't put colon after while in do while loop

  • @anonymouscrawler.official
    @anonymouscrawler.official 9 місяців тому +1

  • @shashankm8981
    @shashankm8981 2 роки тому

    How to run C on windows?

  • @ruok1992
    @ruok1992 2 роки тому +1

    ''while u r outside, buy some milk'' - he neve came back

  • @iltam-sumra-rashupti-elatim
    @iltam-sumra-rashupti-elatim 3 роки тому

    thank you indiaman

  • @jayapriyamoorthy7443
    @jayapriyamoorthy7443 Рік тому

    Python oops concepts post pannunga

  • @mousaismail8757
    @mousaismail8757 2 роки тому

    true comment

  • @jimmymesa
    @jimmymesa 5 років тому +3

    Python is born out from C. However, there is no do-while construct in Python.

  • @ShriKant041
    @ShriKant041 10 місяців тому +1

    🎉🎉🎉

  • @honeyani2167
    @honeyani2167 3 роки тому

    What is meaning of %d sir??

  • @ahmadnaqvi2045
    @ahmadnaqvi2045 Рік тому

    Why don't you have a ; after while (n !=0) in the do while loop code?

    • @handle_gc
      @handle_gc Рік тому

      Because using ; after while() will consider the end of the loop (without body) and throw error.
      In case of do-while it assumes while() as a part of do{}. And ; separates this complete loop body n condition from rest of the statements.

  • @sameer11singh
    @sameer11singh 3 роки тому

    When I am entering a character value itss goes in a infinite loop why!!!???

  • @user-ns5pg8vu5j
    @user-ns5pg8vu5j 8 місяців тому +1

    Where is Semicolon after scanf statement in WHILE LOop😅

  • @CantHandle777
    @CantHandle777 Рік тому

    isnt 0 a integer...btw nice explanation

  • @sruthimajhi5610
    @sruthimajhi5610 Рік тому

    Hey can anyone clear my doubt?
    We need 2 variables right coz there are 2 statements for storing an integer .

    • @handle_gc
      @handle_gc Рік тому

      could you put a time stamp for much clarification for your que?

  • @actionaction007
    @actionaction007 2 роки тому

    Semi colon not used in example ?
    Mistake

  • @capercrusader7129
    @capercrusader7129 2 роки тому

    I like this PRO-gram you did 😘