• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/16

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

16 Cards in this Set

  • Front
  • Back

"while" loops


A _____ is evaluated at beginning of loop. If it evaluates to true, the loop body is executed. If it evaluates to false, control shifts to first statement after loop body.

Repetition-condition

"while" loops


_________ contains one or more C statements. After last statement in _______ is executed, control is shifted back to beginning of loop, and is reevaluated.

body
body

"while" loops


_______ must be made within the loop. That is, something must be done so that eventually evaluates to false. Otherwise we have an "infinite loop."

Progress

while (<_________>)


{


<_________>


}

Repetition condition


body

for(<______> ; <_____> ; <_____>)


{


<_____>


}

Initialization
Repetition condition
Update expression
Body

"for loop"


<___________> statement initializes the loop control variables before loop is executed the first time.

Initializes

"for loop"


<_________> is tested at beginning of loop. If it is true, loop

is executed
Repetition condition

"for loop"


<_____> contains one or more C statements. After last statement in <_____> is executed, control is shifted back to beginning of loop. Then, is executed. Finally, is reevaluated.

Body
Body

"for" loop


As with while loops, the <_____> must define "progress." That is, something must be done so that eventually evaluates to false. Otherwise we have an "infinite loop."

update-expression

List three ways to increment a variable by one.

1. variable = variable+ 1


2. variable++


3. variable += 1

count = count - increment

count -= increment

product = product * product

product *= product

sum = sum/divisor

sum /= divisor

remainder = remainder % 2

remainder %=2

How do you decide when a loop is needed?

Are any steps repeated?


No: No loop required.


Yes: Do you know in advance how many steps are repeated?


No: Use a conditional loop


Yes: Use a counting loop

Code in C for a while loop that counts to 50

int i = 0;




while(i<50);


{


i++;


}