Simple Counting Loops

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

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

View Full Document Right Arrow Icon
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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
9/22/09 Simple Counting Loops Basic example: for( n =9 ; n<N ; n = n + 8 ){ Get something done } -Which is Initialization?
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online