hey guys,
i am just practicing about how to convert a while loop to for loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[code]int i = 2;
while (i <= 9)
{
if (i < 5 && i != 2)
cout << "X";
i++;
}
for loop:
int i=2;
for (int i=2; i<=9; i++)
{
(i<5)&&(i!=2);
cout<<"x"<<endl;
}[code][/
the output should b xx.
but i am getting
x
x
|
x
8 times
can someone please help me to correct the code.
thanks
Please put your code in <code> tags.
Remove the semicolon after 2nd line inside the for loop and there should be an if before that statement.
I assume that this is just a typo error.Be careful while writing your code.