I am learning java as well as android. Almost everything we can do, while a loop we can do in a loop.
I found a simple condition where using a while loop is better than for a loop
if I need to use the counter value in my program, then I think the loop is better than for the loop
Using a while loop
int counter = 0; while (counter < 10) { //do some task if(some condition){ break; } } useTheCounter(counter); // method which use that value of counter do some other task
In this case, I found that the loop is better than for the loop, because if I want to achieve the same thing in the for loop, I have to assign the counter value to another variable.
But is there any specific situation where the while loop is better than for the loop
user831722
source share