do while

do while psuedo codes

Page 1 of 1

4 Replies - 1193 Views - Last Post: 29 September 2008 - 07:33 AM Rate Topic: -----

#1 shaira  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-September 08

do while

Post icon  Posted 26 September 2008 - 08:13 AM

o man sumbody's gotta help me!how do u implement the dowhile concept to practical problems?
Is This A Good Question/Topic? 0
  • +

Replies To: do while

#2 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: do while

Posted 26 September 2008 - 08:22 AM

View Postshaira, on 26 Sep, 2008 - 08:13 AM, said:

o man sumbody's gotta help me!how do u implement the dowhile concept to practical problems?


well say if you want to print out some numbers but only print them out while they are less than a certain value. Then you want to do (a message) while the value is less than some limit.

eg.
int i = 0;
do
{
cout << i << endl;
i++; // increment it each time
} while (i < 100);



so in that you want to print out each value of i and increment it by 1 each time until i is >= 100. So you will get the values 0 1 2 3 4 5 6... 99

Is that what you mean ?

This post has been edited by bbq: 26 September 2008 - 08:23 AM

Was This Post Helpful? 0
  • +
  • -

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: do while

Posted 26 September 2008 - 08:25 AM

A do while loop is basically a while loop, which is always going to be entered, at least once.

A simple while loop:
bool loop = false;
while (loop)
{ // this will never be entered, because loop is already false
    cout << "I just farted";
}


A simple do/while loop:
bool loop = false;
do {
    cout << "I just farted";
} while (loop); // even though loop is false, it will still be executed once

Was This Post Helpful? 0
  • +
  • -

#4 Psionics  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 158
  • Joined: 06-September 08

Re: do while

Posted 26 September 2008 - 12:52 PM

to put it in even simpler terms, a while() loop looks like this:
// if the condition is true, the code
// will execute
while( condition)
{
     body;
}


// and a do-while() loops will
// always run the first time, because
// the condition is at the bottom
do
{
     body;
} while( condition );



so depending on what you want to do, that's how you'll decide which loop you want to use. :)
Was This Post Helpful? 0
  • +
  • -

#5 gelz_143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 20-September 08

Re: do while

Posted 29 September 2008 - 07:33 AM

the do...while loop best suits in situations where users are often questioned YES/NO or in menu-driven programs...
it allows to perform the statements first before evaluating the expression -- which is done at the end.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1