Re: C++ question and advice?

  • From: Dave <davidct1209@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 25 Jul 2010 21:18:38 -0700

A while and a do-while loop share the idea of doing some task or
series of tasks repeatedly as long as some condition is true.  They
have two parts:
-  condition (a boolean check).
-  loop body (I'm referring to this as a task).

The only difference between them is the order of doing the task and
checking that the condition is true.  A while loop checks the
condition first, then performs the task.  A do-while loop performs the
task, then checks the condition.

In a while loop, this has the effect of:
-  when first encountering the loop, if the condition isn't true, then
the task never gets performed.
-  After executing the task, the condition becomes false at some point
(or else you have an infinite loop).

In a do-while loop, this has the effect of:
-  when you first encounter the loop, the task gets performed
regardless if the condition is true.
-  otherwise, it's similar to the while loop.

So, in the above terminology, I would say:
-  do the next homework assignment while there's more homework to be done. Or,
-  while there's more homework to be done, do the next homework assignment.

In effect, you can think of a while loop as a "while, do loop".  Each
has their place depending on what you want.

Hth.

On 7/25/10, Sina Bahram <sbahram@xxxxxxxxx> wrote:
> Stick the menu in a while statement.
>
> Take care,
> Sina
>
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jes
> Sent: Sunday, July 25, 2010 6:03 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: C++ question and advice?
>
> Hi all,
>
> If I instruct a user to enter a choice from a menu, and they enter an
> invalid response, how do I display the menu of choices again
> without retyping the cout statements? For example, cout << "Please select
> your favorite candy:
> 1. Snickers.
> 2. Baby Ruth.
> 3. Milky way. ";
>
> If the user entered number 4,
> How would I print the menu again without typing all those statements?
> And, can somebody explain to me the difference between the do while, and
> while loops?
> Thanks.
> Jes
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: