posted 23 years ago
Hi Khurram
What do you mean by 'efficient'? If you are seeking to learn how to use just one and stick to it because it's 'more efficient', that won't work.
The while loop obviously just checks if a condition is true or false, if true then the code of the loop is executed. A for loop normally declares and initialises a variable, checks a condition, if true executes the code of the loop, then typically increments or decrements a counter.
In this respect, you could say it is carrying out more 'work' outside of the block of code in the loop, so 'less efficient'. However, the point is, you would normally use them for slightly differnt purposes, and the logic required would be the overriding factor in deciding which one to use.
------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
"One good thing about music - when it hits, you feel no pain" <P>Bob Marley