# Beginner question about for loops...

• January 29th, 2012, 02:24 PM
ninjaBob
Hi,
I need to print out a set of numbers that starts at 2, prints out the next 2 numbers, skips the next 2, prints the next 2 and skips the next, etc....... so it should follow the pattern :
2 3 6 7 10 11 14 15 18 19 22 23 etc....

code i have so far...
for (int i =2; i<=255; i++){
//print out i
}

but... i know that this will only print out all the numbers in a row... Any help or suggestions would be great.
Thanks.
• January 29th, 2012, 02:57 PM
Norm
Re: Beginner question about for loops...
Do you know how to use an if statement? You could use an if statement to select when to print and when to skip printing. The trick is determining when to do one and when to do the other.
One way would be to use a counter to see when you had printed two numbers.
Another would be to look at the relationship of the numbers that are printed.
I'll leave the logic to you. You need to spend some time with a paper and pencil, thinking about this before you try writing the code.