(for loop) Need help figure out how to do this another way

Hello guy, I was wondering what is another way to print integer while using "ONE" for loop, BUT without if and conditional operator. I can't figure it out the logical way to do it. for example, here a small code with if statement I know so far.

1
2
3
4
5
6
7
8

 for(int i= number here; conditional here; insert update here)
{
if(true statement)    \\ this shouldn't be here.

cout << i << " ";
}
 
Not sure what you're struggling with? http://ideone.com/kP3xXM
So say I print integer like just prime, perfect, odd, or even number. That easy to do with if/ conditional operator but without it. It difficult. So I don't know what another way to do it while using for loop

Last edited on
Odd and even are trivial: http://ideone.com/pGc8pY

With prime numbers, you run into the intrinsic issue that, well, it's not possible (as far as we know - mathematicians are still hard at work). You could loop through a pre-existing list, though: http://ideone.com/oIzUse
Last edited on
Almost somewhat. I'm trying to print odd integer when I output the min and max range. I made for loop for true statement and I could add if statement inside the for loop to keep the loop going so it doesn't show any even integer when I input first. ex. (if ( integer % 2 == 0)). That easy right, but without the if/conditional operator I couldn't think of other logic way to do that.
Last edited on
Have you been looking at the links I've been posting? This one literally shows you how to do it: http://ideone.com/pGc8pY
That what I use my professor won't accept another for loop only one loop so that where I got lost
I don't think you understand. The first for loop prints only even numbers, and the second prints only odd numbers. I just combined them into one example for convenience - you don't need both of them together.
ah k I'll take a look into this and test it out.
Topic archived. No new replies allowed.