loopc.ppt - 1 int num cout<<" Enter a number"...

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

View Full Document Right Arrow Icon
1 { int num; cout << " Enter a number : "; cin >> num; cout << num << " Squared = " << num * num << endl; cout << num << " Cubed = " << num * num * num << endl; cout << "\nDone!!!\n\n"; }
Image of page 1

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

View Full Document Right Arrow Icon
A loop is a repetition control structure. Parts: Body - statements to be repeated Control statement - decides whether another repetition needs to be made Types: Counted loop - for Logical loop – while or do..while Loops
Image of page 2
When the expression is tested and found to be: True, the body statements will be executed and the control passes back to the expression. False , the loop is exited and control passes to the statement which follows the loop body . FALSE TRUE body statements Expression
Image of page 3

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

View Full Document Right Arrow Icon
loops 4 void main() { int num; cout << " Enter a number : "; cin >> num; while (num != -999) { cout << num << " Squared = " << num * num << endl; cout << num << " Cubed = " << num * num * num << endl; cout << " Enter a number : "; cin >> num; } cout << "\nDone!!!\n\n"; system("pause"); }
Image of page 4
loops 5 Loops Sentinel controlled keep processing data until a special value is entered to indicate that processing should stop Read blood pressures until a special value (like -1) selected by you is read. Count Controlled keep processing data for a specified number of times Read 100 blood pressures. End-of-file Controlled keep processing data as long as there is more data in the file Read all the blood pressures from a file no matter how many are there Flag Controlled keep processing data while a flag condition is true Read blood pressures until a dangerously high BP (200 or more) is read.
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern