loop not exiting

Discussion in 'C Programming' started by sLim, Nov 28, 2009.

  1. sLim

    sLim

    Joined:
    May 17, 2008
    Messages:
    3
    Can anybody tell me why
    Code:
    for(i; currComb & (1 << i) != 0; i++);
    remains looping indefinetly?

    i == 0 in the beginning, I have checked it (I also initialized it to 0, same story)
    currComb == 1
    and currComb & (1 << i) == 0 after the first iteration

    I am using gcc
    sLim, Nov 28, 2009
    #1
    1. Advertising

  2. sLim

    sLim

    Joined:
    May 17, 2008
    Messages:
    3
    Found the reason for the problem. If you have an expression that you want to compare against a value or variable, then the expression has to be in quotes. In my case, "(1 << i) != 0" was evaluated and the result was TRUE every single time.
    Last edited: Dec 2, 2009
    sLim, Dec 2, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Buster Copley

    Exiting a loop half way through

    Buster Copley, Sep 18, 2003, in forum: C++
    Replies:
    5
    Views:
    487
    Buster
    Sep 19, 2003
  2. Steven J. Sobol

    Firefox not exiting (JApplet)

    Steven J. Sobol, Sep 5, 2006, in forum: Java
    Replies:
    4
    Views:
    457
    Steven J. Sobol
    Sep 6, 2006
  3. vineoff

    Exiting from loop

    vineoff, Oct 24, 2005, in forum: C++
    Replies:
    39
    Views:
    933
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Oct 27, 2005
  4. Rodion
    Replies:
    18
    Views:
    213
    Ted Zlatanov
    Mar 26, 2008
  5. Isaac Won
    Replies:
    9
    Views:
    364
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page