While solving coding problems, is there any best practice about loops.
What are the pros and cons of each?
Example: Let's assume I am simply iterating an array. Below is the code snippet:
* Array iteration using While Loop:
int i = 0;
while(i < A.length) {
sout(arr[i]);
i++;
}
* Array iteration using For Loop:
for(int i = 0; i<= A.length-1; i++) {
sout(arr[i]);
}I prefer to write "For Loops" as it's my habit since inception.
Please suggest.
#ForLoopVsWhileLoop