{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Simple Counting Loops

# Simple Counting Loops - Simple Counting Loops Some loops do...

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

9/22/09 Simple Counting Loops Some loops do NOT count: cout << “Input a number from 5 to 30:” << endl; cin >> x; while (x<5 or x > 30){ cout << “C’mon man, in range! Try again:” << endl; cin >> x;

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

View Full Document
9/22/09 Simple Counting Loops Counting Loop: Iterative construct where a loop body is executed a certain amount of times while providing the loop body a counter to specify
9/22/09 Simple Counting Loops “For” Loop: Short hand form of the “while” loop. They take the form: for( initialization ; condition ; iteration_sta tement ) loop_body

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

View Full Document
9/22/09 Simple Counting Loops Initialization : Statement establishing the truth of the invariant before the execution of the loop. Condition (continuation): Expression that repeats until it evaluates to False. Iteration_statement (counter): Expression that continues to change the initial declared value.
9/22/09 Simple Counting Loops Basic example: for( n =9 ; n<N ; n = n + 8 ){ Get something done } -Which is Initialization?

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

View Full Document
9/22/09 Simple Counting Loops Basic example: for( n =9 ; n<N ; n = n + 8 ){ Get something done } -Which is the condition?

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.

{[ snackBarMessage ]}