LoopStatements - Looping Structures Dr. David A. Gaitros...

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

View Full Document Right Arrow Icon
Looping Structures Dr. David A. Gaitros Department of Computer Science
Background image of page 1

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

View Full DocumentRight Arrow Icon
Loop structures 3 Types of loops in C++ while Most flexible No "restrictions" do-while Least flexible Always executes loop body at least once for Natural "counting" loop 2-2
Background image of page 2
while Loop Example Consider: count = 0; // Initialization while (count < 3) // Loop Condition { cout << "Hi "; // Loop Body count++; // Update expression } Loop body executes how many times? 2-3
Background image of page 3

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

View Full DocumentRight Arrow Icon
do-while Loop Example count = 0; // Initialization do { cout << "Hi "; // Loop Body count++; // Update expression } while (count < 3); // Loop Condition Loop body executes how many times? do-while loops always execute body at least once! 2-4
Background image of page 4
Very similar, but… One important difference Issue is "WHEN" boolean expression is checked while: checks BEFORE body is executed do-while: checked AFTER body is executed After this difference, they’re essentially identical! while is more common, due to it’s
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.

This note was uploaded on 04/02/2012 for the course COP 3014 taught by Professor Gaitros during the Fall '11 term at Florida State College.

Page1 / 13

LoopStatements - Looping Structures Dr. David A. Gaitros...

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