dowhile

# dowhile - Programming do-while Loops 2 Prog Fundamentals I...

This preview shows pages 1–6. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Programming do-while Loops 2 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement q q q Syntax do action while (condition) How it works: s execute action s if condition is true then execute action again s repeat this process until condition evaluates to false. action is either a single statement or a group of statements within braces. action condition false true 2 Prog Fundamentals I: do-while Loops /Slide 3 N! int number, factorial, counter; cout << "Enter a positive integer:"; cin >> number; factorial = 1; counter = 1; do{ factorial *= counter; counter++; }while(counter <= number); cout << "The factorial of " << number << " is " << factorial << endl; 2 Prog Fundamentals I: do-while Loops /Slide 4 2N int number, result, counter; cout << "Enter a positive integer:"; cin >> number; result = 1; counter = 1; do{ result *= 2; counter++; }while (counter <= number); cout << "Two raised to the " << number << " power is " << result << endl; 2 Prog Fundamentals I: do-while Loops /Slide 5 Maximum int value; int max=0; do{ cout << "Enter a positive number “ << "(-1 to stop):"; cin >> value; if(value > max) max = value; }while(value!=-1); cout << "The maximum value found is " << max << endl; // input value // maximum value 2 Prog Fundamentals I: do-while Loops /Slide 6 Waiting for a Reply char reply; do{ // do something cout << "Continue(y/n): "; cin >> reply; }while(reply!='n'); ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 6

dowhile - Programming do-while Loops 2 Prog Fundamentals I...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online