For is designed for iteration, you may do an iteration inside a while
loop body also thought, just as well as you may have complex boolean
condition to test in case of a for and just as well as u may do other
operation but incrementing or decrementing in case of a for loop.
However there are many differences between for and while, like for
example, in case of a while u need to have declared the variable u use
in the boolean expression before. But then again a for expression
like

int i=0;
for(;i<5;System.out.println(i)){
i++;
}

is legal and will have the exactly same effect as

int i=0;
while(i<5){
i++;
System.out.println(i);
}

Then comes the do{}while(); which guarantees going through the loop
body at least once and the enhanced for wich also iterates. My
personal opinion is that you can simulate for with a while and while
with a for but is much up to readability, elegance and lack of
duplication in the code and the easyest way to do what you have to do.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to