1_Review_6-1 - 1 CIS 15AG Review Chapter 6: Repetition...

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

View Full Document Right Arrow Icon
CIS 15AG Review Chapter 6: Repetition Repetition many problems require an action or a set of actions to be repeated; this requirement can be accomplished in two different ways: using loops or using recursion. Loop – a statement that controls the execution of an action (or a series of actions) that is continually repeated as long as a condition is reached. Iteration – a single execution of the action(s) in a loop. Posttest Loop test after action (s) Pretest Loop test before action (s) Counter-Controlled Loop – the number of iterations is known in advance (repeat "this" n times) Event-Controlled Loop – the number of iterations is not known in advance (repeat "this" as long as some condition is true) Loops in C – there are three loop statements: do …while while for All of them can be used for counter-controlled and event-controlled loops, but the for loop is most naturally used for counter-controlled loops. do …while // posttest loop 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
CIS 15AG Review Chapter 6: Repetition while // pretest loop for // pretest loop 2 c = 0; do { x = x – y; c = c + 1; }while ( x >= y ); do x = x – y; while ( x >= y ); q = 0; while ( x >= 0 ) { x = x – y; q = q + 1; } r = x; while ( x >= y ) x = x - y; x x - y x y True x x - y x y True c c + 1 c 0 True x x - y x y True x x - y q q + 1 q 0 x r x
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Spring '10 term at DeAnza College.

Page1 / 5

1_Review_6-1 - 1 CIS 15AG Review Chapter 6: Repetition...

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

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