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
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
😂😂😂
Exactly 😂😂😂
He actually did that "on purpose".
Same doubt bro
Right bro
Whenever he says "right?", I fear that in the very next moment he'll say ," wrong! !"😄😄
Printf also ; missing
Same
Me to
Me too🤣
@@chocolittlecrushon201is that mean the structure of programming is wrong...? I don't know just asking could you tell me please 😊
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.......
Minutes of struggle solved in seconds
Watching you grow. Thanks for sharing
What fonts did you use in this tutorial? very interesting, I want to use it too.
Every time I watch your teaching videos I'm getting better, Thank you so much
Thanks for the explanation, now I understand
thank you for ur amazing explanation.
a small note: there is a missing ';' at the last do-while example you entere.
Information was clear and concise.
Thanks heaps for your efforts :)
You are a very great teacher!
Thank you sir. All my doubts are cleared
I love this explanation.
Thank you so much this was really helpful
Thanks! It was a fast and simple explanation to understand. Nice video ^_^
Excellent explanation sir VERY HELPFUL VIDEO
what happen if we put semi colon in after while loop
thank you so much. Now I understand difference between while and do while loop
Your explanations are the best out there. If you have a paid course, I will sign up for it.
sir your explaination is very nice, thank you sir :)
really extraordinary
My 2 hours work you solved in 2-3 minutes sir I am sure that your channel will be sure in top 10 ❤
Thanks so much!
im learning c++ thanks a lot
great instructor
For (int I=o;i
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);
}
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);
}
@@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. :)
I want to know what compiler you are using in your lectures
It was really helpful for me sir ❣️❣️❣️
good content ;deep and well structured.
Thank you 😊
neso academy is the best
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.
Smart
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?
He didn't run the 2nd program...
Sir 🗣️a small note: there is a missing 👉';' at the last do-while example you entere.✍️
What a fantastic tutorial, I struggled with this for a long time before seeing your video. Thank you
Same here!
Thank you sir for this video it's really good!!!
thanks!
amazing, short and accurate!!!
Tq very much sir and your method is very easy
Sir in example of do and while u not putted semicolon in do while loop
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.
I like this method of teaching
Nice share keep it up
U told that in do while loop exactly in while statement it should be ended with semicolon right??
Thats it ....I hoped u will post Programming videos.....I will watch whole of them but keep posting ....and also on java and C++
what's the meaning of semicolon at the end of do while loop please dry run this loop
I will learn full C from neso academy.
Hello Sir! How about you make a video about turning for loop into do while loop.. It will be very helpful. Thank you!
Thank u
Awesome
Sir aap jo next example diye the usme while loop k baad semicolon nhi lagye he
Thnx sir
🤔doesn't got any error for not using semicolon in do while???
Putting a semicolon at the end is probably necessary for the compiler to parse the source code properly.
great
Sir plz make vdo on difference between definition and declaration of variables in c
On 3:55, the program of do-while , there should be a semicolon after while
r u sure
Same doubt
Ha yes.dude
so its literally another syntax to add an if statement in a loop?
int b=0;
int c=9;
do {
if(c
Can i solve the same problem with for loop?
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?
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;
}
Where are you writing the code?
I'm using replit and this code is not working
Instead of that printf and scanf function we can just simply initialise n=1 in while loop
But in the question user need to give the value
Thnx ...very helpful ;_;
4:00 look at the while program . You are not terminating the scanf function
It's good 👍
4.10 you missed the semicolon in do while loop's side
It is because he too didn't has used do- while much
I think it is @2:42 :-)
Thank you i understand but second example your missing semicolon sir but sir thank you giving explanation.
Interesting.
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)]
Super
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;
}
2:41 displayed do while loop program no semi coloum
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
We can just initialize n to some non 0 value and use the while loop.
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;
}
what does the ,,&" sign before variable ,,i" mian?
It can also be n>0 ryt?
do nested loop in C language please
you are smart
why your codes are not working in online complier
4:01 why you didn't put ; on do while loop
You didn't write semi colon after while in the program of do while when showing the program
Sir you didn't put colon after while in do while loop
❤
How to run C on windows?
''while u r outside, buy some milk'' - he neve came back
thank you indiaman
Python oops concepts post pannunga
true comment
Python is born out from C. However, there is no do-while construct in Python.
🎉🎉🎉
What is meaning of %d sir??
Why don't you have a ; after while (n !=0) in the do while loop code?
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.
When I am entering a character value itss goes in a infinite loop why!!!???
Where is Semicolon after scanf statement in WHILE LOop😅
isnt 0 a integer...btw nice explanation
Hey can anyone clear my doubt?
We need 2 variables right coz there are 2 statements for storing an integer .
could you put a time stamp for much clarification for your que?
Semi colon not used in example ?
Mistake
I like this PRO-gram you did 😘