Re: How to convert for, statements into while loops?

  • From: Alex Hall <mehgcap@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 18 Jul 2010 21:44:45 -0400

Here is an example which you can use to convert your code.

for
(i=0;i<10;i++){
cout << i;
}

//same thing:

int i=0;
while(i<10){
cout << i;
i++;
}

On 7/18/10, Jes <theeternalkid@xxxxxxxxx> wrote:
> Hi all,
> I got my program to work correctly, but now I want to learn how to convert
> the pre test loop, the for statement, into a while loop.
> ***code**
> //Ch8lab2.cpp
> //Displays one or more multiplication tables
> //Created/revised by Jes Smith on July 18, 2010
>
> #include <iostream>
>
> using std::cout;
> using std::cin;
> using std::endl;
>
> int main()
> {
>       //declare variables
>       char anotherTable = ' ';
>       int multiplicand        = 0;
>       int product                     = 0;
>
>       do
>       {
>               //get the multiplicand
>               cout << "Enter the multiplicand: ";
>               cin >> multiplicand;
>
>               //display the multiplication table
>               for (int multiplier = -1; multiplier < 10; multiplier += 1)
>               {
>                       product = multiplicand * multiplier;
>                       cout << multiplicand << " * " << multiplier
>                               << " = " << product << endl;
>               }       //end for
>
>               cout << endl;
>               cout << "Display another multiplication table? (Y/N) ";
>               cin >> anotherTable;
>       } while (toupper(anotherTable) == 'Y');
>       return 0;
>
> } //end of function


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: