loop not exiting

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

  1. sLim

    sLim

    Joined:
    May 17, 2008
    Messages:
    3
    Likes Received:
    0
    Can anybody tell me why
    Code (Text):
    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. Advertisements

  2. sLim

    sLim

    Joined:
    May 17, 2008
    Messages:
    3
    Likes Received:
    0
    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. Advertisements

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:
    663
    Buster
    Sep 19, 2003
  2. Steven J. Sobol

    Firefox not exiting (JApplet)

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

    Exiting from loop

    vineoff, Oct 24, 2005, in forum: C++
    Replies:
    39
    Views:
    1,141
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Oct 27, 2005
  4. ma3mju

    Processes not exiting

    ma3mju, Jul 31, 2009, in forum: Python
    Replies:
    14
    Views:
    837
  5. Derek Lewis
    Replies:
    2
    Views:
    228
    Zachary P. Landau
    Dec 4, 2003
  6. Marcin Jurczuk

    [rails] dispatch.fcgi do not exiting ..

    Marcin Jurczuk, Nov 2, 2005, in forum: Ruby
    Replies:
    1
    Views:
    313
    Jamis Buck
    Nov 2, 2005
  7. Rodion
    Replies:
    18
    Views:
    322
    Ted Zlatanov
    Mar 26, 2008
  8. Isaac Won
    Replies:
    9
    Views:
    798
    Ulrich Eckhardt
    Mar 4, 2013
Loading...