Lecture 9:  Iteration

Activity:



We saw in today's lecture the introduction of loops, specifically the "for" and the "while" loops.  In your group, please discuss the following questions.

1.  Can every while loop be re-written as a for loop?  If yes, please describe how you would convert a generic while loop into a for loop.  If no, give an example of a while loop that cannot be re-written as a for loop.
 
 
 
 
 
 
 

2.  Can every for loop be re-written as a while loop?  (Hint:  recall today's lecture)  If yes, please describe how you would convert a generic for loop into a while loop.  If no, give an example of a for loop that cannot be re-written as a while loop.
 
 
 
 
 
 
 

3.  Let's define a new language called C-.  C- is the C language with no for loops.  Do C and C- have the same expressive power?  (Expressive power means that if you can write a program in C then you can write a program in C- and if you can write a program in C- you can write a program in C.)  Why or why not?