{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

LoopStatements - Looping Structures Dr David A Gaitros...

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
Image of page 4