Results 1 to 2 of 2
  1. #1
    vb89 is offline Member
    Join Date
    Feb 2012
    Rep Power

    Default 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++)
      // not sure how to go about this 
      // 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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default 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.

Similar Threads

  1. issue with loop or IDE
    By neoginn in forum New To Java
    Replies: 3
    Last Post: 10-28-2011, 06:59 AM
  2. Loop Issue
    By burrish in forum New To Java
    Replies: 11
    Last Post: 09-25-2011, 09:26 PM
  3. using the mousedrag in a conditional loop
    By trishtren in forum New To Java
    Replies: 4
    Last Post: 04-23-2011, 03:55 PM
  4. Issue with nested for loop
    By sunshine64 in forum New To Java
    Replies: 5
    Last Post: 02-03-2011, 02:45 AM
  5. [Q] Loop issue (while loop)
    By iriscience in forum New To Java
    Replies: 9
    Last Post: 01-31-2011, 04:21 PM

Posting Permissions

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