{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

chtp5_04-TIF-Beta

chtp5_04-TIF-Beta - 4.1Introduction 4.1 Which is not a...

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

4.1  Introduction 4.1. Which is not a repetition struction? a) continue b) for c) while d) do while ANS: (a) 4.2.Which statement is used to skip the remainder of the body of a repetition struction and proceed with the next iteration of the loop? a) skip b) proceed c) continue d) jump ANS: (c) 4.2  The Essentials of Repetition 4.3 ________ repitition is sometimes called definite repitition. (a) counter-controlled (b) sentinel-controlled (c) variable-controlled (d) none of these ANS: (a) 4.4 ________ repitition is sometimes called indefinite repitition. (a) counter-controlled (b) sentinel-controlled (c) variable-controlled (d) none of these ANS: (b) 4.5. Which statement is false? a) Counter-controlled repetion is sometimes called definite repetition. b) Sentinel-controlled repetition is sometimes called indefinite repetition. c) The sentinel value typically indicates “end of data.” d) In counter-controlled repetition, the control variable is always incremented by 1 each time the group of instructions is performed. ANS: (d)

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

View Full Document
4.6. Which statement is true? a) Sentinel values are used to control repetition when the precise number of repetitions is known in advance. b) Sentinel values are used to control repetition when the loop does not include statements that obtain data each time the loop is performed. c) Sentinels must be distinct from regular data items. d) Sentinel-controlled repetition is often called definite repetition. ANS: (c) 4.3 Counter-Controlled Repitition 4.7 Which of the following does counter controlled repetition not require? (a) an initial value (b) a condition that tests for the final value (c) an increment or decrement by which the control variable is modified each time through the loop (d) counter controlled repetition requires all of the above ANS: (d) 4.8 The statement while ( -- counter >= 1 )    printf( “%s\n”, counter % 2 ? “even” : “odd” ); can not be rewritten as (a) while ( -- counter >= 1 )    if ( counter % 2 ) printf( “even” ); else  printf( “odd” ); (b) while ( counter >= 1 )    if (counter % 2) printf( “even” ); else  printf( “odd” ); --counter; (c) while ( counter >= 1 )    {    if ( counter % 2 ) printf( “even” ); else  printf( “odd” ); --counter;    }
(d) do   { printf( “%s\n”, counter % 2 ? “odd” : “even” ); --counter;   }while ( counter >= 2 ); ANS: (b) 4.9 Which of the following is a bad programming practice? (a) indenting the statements in the body of each control structure (b) using floating-point values as the counter in counter-controlled repetition (c) using more than three levels of nesting (d) placing vertical spacing above and below control structures ANS: (b) 4.10. Which is not always required by counter-controlled repetition? a) The name of a control variable (or loop counter).

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 13

chtp5_04-TIF-Beta - 4.1Introduction 4.1 Which is not a...

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

View Full Document
Ask a homework question - tutors are online