This may be a stupid question, but how does the efficiency of a while loop compare to that of a for loop? I\'ve always been taught that if you can use a for loop,
The performance difference between for loop and while loop is not a big issue because modern compilers can generate same machine code for both loops and secondly both loops require same operations:
In general you should use for loop in your code for the following reasons:
while loop, hence it helps in better memory management.I hope that makes sense and would help.