|
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
Inspector General
Join Date: May 2001
Posts: 493
|
loops: for, while, do while: just a matter of preference
just a quick question.
I am very comfortable with "for" loops. from my understanding they can achieve everything that while and do while can. is it just a matter of preference or are the others better for different scenarios? i don't find the info on livedocs to highlight much of a difference. thanks for your input carl
__________________
some of my flash stuff |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
As you know, for loops are a coding shortcut a while loop that uses an incrementing counter.
many while loops are structure like so:
These tend to work well as for loops.
However, there are other cases, where a while loop is sufficient. Especially, if you don't need the setup or increment steps. For example:
such as
I tend to use a for loop only if the setup, condition and increment are all simple and involve the same variable. Otherwise, the code is probably easier to read in a while loop. If there is a difference in performance, it is quite small and not worth worrying about. Trying to speed up your code? Changes in design and algorithms will give you big gains. Little changes in coding style only give you little gains. Last edited by jbum; 10-21-2004 at 02:11 PM. |
|
|
|
|
|
#3 |
|
Inspector General
Join Date: May 2001
Posts: 493
|
thanks so much for your thorough and clear response. I learned something.
-also a big fan of your work... wow. carl
__________________
some of my flash stuff |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|