I read that while loop is used when number of iterations are unknown and for loop is used when number of iterations are known ... such as when I have to print a statement 5 times I have to initialize the variable in both while and for loop and also I need to give iteration condition in both (i++) and i also have to mention condition of iteration so that it loops only 5 times ... then whats the difference ? can someone pls tell with an example
for(int i=0;i<5;i++){
cout<<"Hello";
}
int i=0;
while(i<5){
cout<<"hello";
i++;
}