1. Member Join Date
Feb 2012
Posts
2
Rep Power
0

## Conditional loop issue...

I'm trying to write a loop that will print to the buffer based on the following conditions:

Java Code:
```int maxNum = 7;

int a = 0;  //1,4,5,8,9,12,13... infinity
int b = 2;  //3,6,7,10,11,14,15... infinity
// the above variables don't not need to be an array list or anything, i'm just try to illustrate
//the possible values of variables a and b

for(int i=0;i<maxNum;i++)
{
// if i == 0,1,4,5... print a
// if i == 2,3,6,7... print b
}```
The example above is a dumbed down version of what I'm trying to do, I'm mainly interested in the logic. Please assume that variables a and b will have an infinite amount of numbers -- for the sake of this example. The main point that i'm trying to illustrate is the pattern in the variables a and b; a starts with 0 and 1, and then every other two numbers are found in the variable a, and the opposite for b. I'm trying to figure out how to write logic that will print out values a or b based on the pattern described above inside a loop.
Last edited by vb89; 02-02-2012 at 07:29 PM.  Reply With Quote

2. ## Re: Conditional loop issue...

Do you have a formula for detecting the when the variable has one of the values?
It looks like: 2 for me and two for you and two for me and two for you.
You should be able to work out some logic for this with counters.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•