loop - Programming Summary of Loops Prog Fundamentals I:...

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

View Full Document Right Arrow Icon
Summary of Loops Programming
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Prog Fundamentals I: Summary of Loops /Slide 2 Which Loop to Use? for loop for calculations that are repeated a fixed number of times controlled by a variable that is changed by an equal amount (usually 1) during each iteration while loop The number of iterations depends on a condition which could be changed during execution. Example: working with user input. In some situations the code segment should not be executed at all. do-while loop The code segment is always executed at least once. Otherwise, the situations when do-while loops are used are very similar to those when while loops are used.
Background image of page 2
2 Prog Fundamentals I: Summary of Loops /Slide 3 How to Stop a Loop Known number of iterations before the loop stops ( for ). Test for a user-controlled condition before or after each iteration ( while , do-while ). Use the break command.
Background image of page 3

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

View Full DocumentRight Arrow Icon
2 Prog Fundamentals I: Summary of Loops /Slide 4 break break is used when we want to terminate a loop before it ends in a normal way.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/07/2011 for the course COMP 102 taught by Professor Daniel during the Spring '08 term at HKUST.

Page1 / 15

loop - Programming Summary of Loops Prog Fundamentals I:...

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

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