473,657 Members | 2,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference between while and do while

Hi. What's the difference between while and do while?
Dec 24 '07 #1
9 19042
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*********@st udent.uts.edu.a uwrote in message
news:47******** *************** @news.optusnet. com.au...
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*********@st udent.uts.edu.a uwrites:
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_Keit h) <ks***@mib.or g>
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.individua l.net>,
osmium <r1********@com cast.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.individua l.net>,
osmium <r1********@com cast.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*****@xmissio n.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
21911
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
3202
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). thanks mahesh
147
10080
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 is "no" but I'd like to know what the consensus is
6
71964
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
1972
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 get to work. The exercise asks that you create a game that makes the user guess a number from 1-100, and you tell the user "lower" or "higher" as they input their guesses, until they guess the correct number, at which point you then tell the user "Correct". I tried using the While Loop, and...
4
2859
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. Here goes the pseudo code int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { //Register class CMyEventHandler : public IDispatch with
23
3559
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 help me please??? code is below: package testBean; import java.io.*;
11
25514
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; }while (x < 3); What's the point of having the semicolon after the (x < 3)? Why can't the
1
1374
by: m konstantakis | last post by:
#include <stdio.h> int main(void) { int currentprice,upcomingprice; int currentprice1,currentprice2,currentprice3; int upcomingprice1,upcomingprice2,upcomingprice3; int difference; float gallons; printf( "Enter the water consumption \n ", gallons ); scanf( "%f", &gallons);
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.