how to include a nested loop for "sum"???

for (int i = 0; i < 4; i++)
{
if (i % 3 == 0) continue;
sum += i;
} return 0;
}
You're not outputting the sum variable to see the result.
Also, when you create a variable, it's initialized with a garbage value, so it's good practice to initialize it with something you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;


int main()
{
	// initialize the variable to 0.
	int sum = 0;

	for( int i = 0; i < 4; ++i )
	{
		if( i % 3 == 0 )
			continue;

		sum += i;
	}

	cout << "Sum is: " << sum << endl;

	return 0;
}
Sum is: 3
Topic archived. No new replies allowed.