Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > loop not exiting

Thread Tools

loop not exiting

sLim sLim is offline
Junior Member
Join Date: May 2008
Posts: 3
Can anybody tell me why
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
Reply With Quote
sLim sLim is offline
Junior Member
Join Date: May 2008
Posts: 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 by sLim; 12-02-2009 at 08:35 PM..
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Problem with loop control LAST exiting prematurely Rodion Perl Misc 18 03-26-2008 10:18 PM
Firefox not exiting (JApplet) Steven J. Sobol Java 4 09-06-2006 06:49 PM
Exiting from loop vineoff C++ 39 10-27-2005 09:16 PM
Exiting a loop half way through Buster Copley C++ 5 09-19-2003 03:29 PM