/Homework 9 – October 25

 

Questions about fixed count iterations

 

Name ___________________   Language  (circle the one to which the answers below apply)  Pascal   Java    Ada

 

Definition:  Fixed-count iterations (often referred to as FOR loops) are controlled by the loop control variable (abbreviated LCV)

 

  1. What types are permitted for the LCV?

char, int, double  

 

  1. What is the scope of the LCV (i.e. where is it known? where can it be printed ?

only inside the loop if it is declared in the loop header, otherwise everywhere

 

  1. Can the LCV be modified by the programmer within the iteration body?

yes but programmer shouldn’t do it

 

  1. What is the value of the LCV after normal termination of the iteration?

one unit more or less than then modification value  depending on whether the modification is incrementing or decrementing

 

  1. When are the final (and increment/decrement) expressions evaluated?

every time around the loop

 

  1. Is an increment other than successor permitted?

yes.  if i  is the loop control variable,  the modification can be i++, i--, i=i+0.5

 

  1. Is iteration backward through a range allowed and if so, how is it specified?

yes the modification can be i --

 

  1. Is transfer into the iteration permitted and if so, what effect does it have on the LCV?

no

 

  1. How is the iteration body delimited?

with curly braces  which are only needed if there is more than one statement in the body

 

  1. Is it possible to transfer out of the iteration before the iteration has completed and if so, how do you do it?

yes,  with a break statement