208 Day 09 repititon2

# 208 Day 09 repititon2 - 4002-208Intro to Prog[in C]Day...

This preview shows pages 1–9. 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 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: 4002-208Intro. to Prog. [in C++]Day 09More on RepetitionObjectives•Review while loop•for loop•Auto increment operator•Accumulator•Compound operator4002-2082Review of while loopwhile (loop condition){loop body}•Loop condition is a Boolean condition.•Execute loop body if loop condition is true.4002-2083Use a Sentinel Loop//read first input valuewhile (input is invalid){//execute code//read another input value}4002-2084Finger work•Run the program grades.cpp•Add a data validation loop to ensure score is between 0 and 100, inclusively.4002-2085for loop•Most common use is to execute the loop body a specific number of times•Basics–Initialize counter–Test counter – halt loop when test is false–Change counter•for(initialize counter; test counter; change counter)4002-2086Perform code a specific number of timesfor ( int counter = 1 ;counter <= number_of_times ;counter=counter+1 ){//code to repeat}4002-2087Print 1 to 10•Initialize counter: int k = 1Test counter: k<=10•Change counter: k=k+1•for (int k=1; k<=10; k=k+1){cout << k << endl;}4002-2088Counter...
View Full Document

{[ snackBarMessage ]}

### Page1 / 15

208 Day 09 repititon2 - 4002-208Intro to Prog[in C]Day...

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

View Full Document
Ask a homework question - tutors are online