472,353 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Difference between while and do while

Hi. What's the difference between while and do while?
Dec 24 '07 #1
9 18933
In While loop the condition is tested first and then the statements are
executed if the condition turns out to be true.
In do while the statements are executed for the first time and then the
conditions are tested, if the condition turns out to be true then the
statements are executed again.

A typical scenario to use do While loop.
I would like to get a specified input from user. Here first I will get the
input then I will check whether we got the specified input other wise we
will again ask for the input.
eg.,
do
{
char input;
printf("say yes or no :(y/n)";
input = getchar();
}while(!(input == 'y' || input == 'n'));
"Logan Lee" <lo*********@student.uts.edu.auwrote in message
news:47***********************@news.optusnet.com.a u...
Hi. What's the difference between while and do while?

Dec 24 '07 #2
Logan Lee wrote:
Hi. What's the difference between while and do while?
Where do you see the test?

--
Ian Collins.
Dec 24 '07 #3
Logan Lee <lo*********@student.uts.edu.auwrites:
Hi. What's the difference between while and do while?
What does your textbook say?

I'm not trying to be unhelpful. This is very elementary question,
something that any decent textbook or tutorial should answer.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 24 '07 #4
Logan Lee wrote:
Hi. What's the difference between while and do while?
Are you the same "Logan Lee" who's lecturing us all on
how to do static code analysis? If you're going to analyze
code, wouldn't it be a good idea to learn the language first?

Get a C textbook. Usenet is a fine way to transmit some
kinds of knowledge, but it's not well suited to delivery of
"the 101 course."

--
Eric Sosman
es*****@ieee-dot-org.invalid
Dec 24 '07 #5
"Logan Lee" writes:
Hi. What's the difference between while and do while?
A do while is used for a block of code that must be executed at least once.
These situations tend to be relatively rare, thus the simple while is more
commonly used.
Dec 24 '07 #6
In article <5t*************@mid.individual.net>,
osmium <r1********@comcast.netwrote:
>"Logan Lee" writes:
>Hi. What's the difference between while and do while?

A do while is used for a block of code that must be executed at least once.
These situations tend to be relatively rare, thus the simple while is more
commonly used.
The best way to express this is that:

do {<statement>} while (<expr>);

is equivalent to:

{};
while () do {};

i.e., do it once, then enter into a normal "while" loop.

Dec 24 '07 #7
Kenny McCormack wrote:
In article <5t*************@mid.individual.net>,
osmium <r1********@comcast.netwrote:
>>"Logan Lee" writes:
>>Hi. What's the difference between while and do while?

A do while is used for a block of code that must be executed at least
once. These situations tend to be relatively rare, thus the simple
while is more commonly used.

The best way to express this is that:

do {<statement>} while (<expr>);

is equivalent to:

{};
while () do {};

i.e., do it once, then enter into a normal "while" loop.
Yes. In C syntax that would be:

{ };
while () { }

You could also place the loop at the bottom of the previous block.

Dec 25 '07 #8
ga*****@xmission.xmission.com (Kenny McCormack) writes:
{};
while () do {};
The semicolons and the "do" keyword should be dropped (and some
content should be added to the parentheses and braces).
--
Peter Seebach on C99:
"[F]or the most part, features were added, not removed. This sounds
great until you try to carry a full-sized printout of the standard
around for a day."
Dec 25 '07 #9
Logan Lee wrote:
Hi. What's the difference between while and do while?
You've repeatedly asked this newsgroup very elementary questions about
C. Would you please bother reading an elementary C textbook to find out
the answers to these questions? If you've already done so, and you still
have this many questions about matters this elementary, may I politely
suggest that computer programming doesn't seem like a good career choice
for you?
Dec 25 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Rick | last post by:
Hi, For portability, can an issue arise if we use while(1) for an infinite loop in C? If so, should we then use for(;;)? Thanks, Rick
7
by: Mahesh Kumar Reddy.R | last post by:
Hi Can any body resolve this.. In what cases one of the loop constructs better than other interms of speed , space and any other (redability). ...
147
by: Michael B Allen | last post by:
Should there be any preference between the following logically equivalent statements? while (1) { vs. for ( ;; ) { I suspect the answer...
6
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
12
by: Howard | last post by:
Hello everyone (total VB.NET beginner here), I'm reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came across an exercise that I can't...
4
by: Uday Bidkar | last post by:
I am trying to register my interface with IConnectionPoint of outlook reminders to capture some Outlook Reminder events and having some issues....
23
by: Naha | last post by:
Hi Guys, I am trying to print lines of data from a text file on to a webapge using jsps. but i can not get the while loop to work. Can Someone...
11
by: Rene | last post by:
Quick question, what is the point for forcing the semicolon at the end of the while statement? See example below: x = 0; do { x = x + 1;...
1
by: m konstantakis | last post by:
#include <stdio.h> int main(void) { int currentprice,upcomingprice; int currentprice1,currentprice2,currentprice3; int...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.