How to output after a certain amount of iterations in a for loop

Hey all,

I am trying to write a for loop and add a cout statement on it after a certain amount of iterations. I know i look like an idiot asking this, but how do I go about doing that?

I have code that iterates 10 times. After the 10th time, I want it to display "Congrats, you won!" but I am not sure how to go about it. This is the code I came up with so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for(int i = 0; i < 10; i++)
{
	if(function == true)
	{
		.....
	}
	else
	{
		.......
	}
	
	if(i = 9)
	{
		cout << "You won!" << endl;
	}
}


but if I use this,
it seems to iterate after the first loop and end the loop
I know i am making a stupid mistake somewhere. How do i fix it?

Thanks
--
Last edited on
if you want print AFTER 10 times:

1
2
3
4
5
6
for( int i = 0 ; i < 10 ; ++i )
{
     // code
}

 std::cout << " congratulation..you wont "


else if you want to print AT 10 times:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for(int i = 0; i < 10; i++)
{
	if(function == true)
	{
		.....
	}
	else
	{
		.......
	}
	
	if(i == 9)
	{
		cout << "You won!" << endl;
	}
}
Thanks! I needed it to show when i was 10 so the second code worked perfectly!
of nothing.

bye
Topic archived. No new replies allowed.