Continue in loop

Continue in loop

Write a program that outputs values from 1 to 100 seperated by commas. Use continue to skip every odd number devisable by 3.

Expected Output

1, 2, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16 ... 98, 100, 

Answer

#include <iostream>

int main() 
{
    for (int i = 1; i <= 100; ++i) 
    {
	// Check if it's an odd number (not divisible by 2) and divisible by 3
	if (i % 2 == 1 && i % 3 == 0)
		continue;

	std::cout << i << ", ";
    }
}
Questions