While loop to For Loop

Convert the following while liio to a for Loop

1
2
3
4
5
6
double f=0.1;
while(f<0.9 && flag==1)
{
f+=0.1
cout<<f/2<<endl;
}

Last edited on
1
2
3
4
5
6
7
8
for (double i = 0.1; double i < 0.9; i++)
{
  if (flag ==1)
  {
     i+=0.1;
     cout << i/2 <<endl;
  }
}
Last edited on
@imohamme5
Nope, your loop is wrong.

Try this:
1
2
3
4
for(double f=0.2; f<0.9 && flag==1; f+=0.1)
{
cout<<f/2<<endl;
}
Topic archived. No new replies allowed.