Thread: Need help wit a for loop

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    Need help wit a for loop

    x y z state
    0 0 0 0
    0 0 1 1
    0 1 0 2
    0 1 1 3
    1 0 0 5
    1 0 1 6
    1 1 0 7
    1 1 1 8

    hello I'am trying to write a for loop that will increment and when it does it will go from state 1 to 2 and so on. But this must be done keeping in mind that x,y and z are all variables and cannot be assigned a value. I wish to know how to increment x,y and z to go from 1 state to another. I appriciate any help anyone can give me
    Last edited by HAssan; 05-07-2007 at 07:51 AM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by HAssan
    But this must be done keeping in mind that x,y and z are all variables and cannot be assigned a value.
    The very definition of a variable is in part something that can be assigned a value.

    You seem to need a nested loop:
    Code:
    int x, y, z;
    for(x = 0; x <= 1; ++x )
        for( y = 0; y <= 1; ++y )
            for( z = 0; z <= 1; ++z )
            {
                /* Do something based on the current value of x, y, and z, i.e. the state */
            }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by HAssan View Post
    x y z state
    0 0 0 0
    0 0 1 1
    0 1 0 2
    0 1 1 3
    1 0 0 5
    1 0 1 6
    1 1 0 7
    1 1 1 8

    hello I'am trying to write a for loop that will increment and when it does it will go from state 1 to 2 and so on. But this must be done keeping in mind that x,y and z are all variables and cannot be assigned a value. I wish to know how to increment x,y and z to go from 1 state to another. I appriciate any help anyone can give me
    What about state == 4??


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help me out Unrgent wit a cross word program
    By rags in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 11:12 AM
  2. M.Server 2000 connected wit C++Builder 6 Null to string problem
    By Leite33 in forum Windows Programming
    Replies: 0
    Last Post: 07-22-2006, 06:36 AM
  3. Plz help wit my program
    By psychaospath in forum C++ Programming
    Replies: 4
    Last Post: 03-10-2006, 05:13 PM
  4. Program Has Stuff Wrong Wit It
    By oobootsy1 in forum C++ Programming
    Replies: 5
    Last Post: 08-12-2003, 08:38 PM
  5. help wit functions
    By Nikisha in forum C++ Programming
    Replies: 11
    Last Post: 03-30-2003, 04:21 PM