Lecture 7
25
•while can replace for:
• int i = 0;
• while (i < 3) {           for(int i=0;i<3;i++){  
•   System.out.println(i);      //ditto  
•   i = i + 1;              }
• }
•for can replace while:
• boolean more = true;        for(  ; ask();  ) {
• while ( more ) {               // do something
•   // do something           }
•   more = ask();
• }
•For loop advantages:
–fewer lines, control all on one line, elegant, idiomatic
•
for and while
note empty
start                 step
start
test
step