Hey all, Im doing my SDD homework and im stuck with this C++ question:
Rewrite the following code segment without using break and continue.
for (int i=0; i < 30; i+=2)
{
if (i % 2)
continue;
if (i % 3)
cout << i << endl;
if (i % 7)
break;
}
The problem is I've tried so many times with different coding but can't get the exact output (which is 2).
This is one of the example I tried, but it came back with infinite numbers of 2
for (int i=0; i < 30 || ((i % 7) == false);i+=2)
{
while (((i % 2) == false) && (i % 3))
{
cout << i << endl;
}
}
Would someone please help me out with this problem, thanks in advance
Rewrite the following code segment without using break and continue.
for (int i=0; i < 30; i+=2)
{
if (i % 2)
continue;
if (i % 3)
cout << i << endl;
if (i % 7)
break;
}
The problem is I've tried so many times with different coding but can't get the exact output (which is 2).
This is one of the example I tried, but it came back with infinite numbers of 2
for (int i=0; i < 30 || ((i % 7) == false);i+=2)
{
while (((i % 2) == false) && (i % 3))
{
cout << i << endl;
}
}
Would someone please help me out with this problem, thanks in advance