{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

1_Review_6-1

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

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

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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online