Thread: for loop not working properly

  1. #16
    Registered User
    Join Date
    Feb 2012
    Posts
    116
    my aim is that the loop continues until the flag is raised. So when flag=1 this means the flag was raised and the loop should finish. Ill take the 0 out, i agree its misplaced thanks

  2. #17
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    for(flag=0; flag != 1; )
    guess
    Code:
    flag=0;
    while( ! flag ){
       ....
    }
    would be better here
    Kurt

  3. #18
    Registered User
    Join Date
    Feb 2012
    Posts
    116
    that seems to have worked much better. Thank you. Its still not functioning perfectly but hopefully i can take it from here. I really appreciate you taking the time to help me, thanks so much

  4. #19
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by David_Baratheon View Post
    So when flag=1 this means the flag was raised and the loop should finish.
    No! You're misusing some basic C syntax:
    flag = 1 is an assignment, meaning that you are setting the variable flag to have value 1
    flag == 1 is a comparison, meaning that you are testing whether flag and 1 have the same value

    So what you're doing is assigning 1 to flag rather than testing whether flag is 1. You should re-read your text book or course notes. This is fundamental stuff.
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. while loop not working properly
    By Shinzu911 in forum C Programming
    Replies: 3
    Last Post: 04-24-2012, 10:01 AM
  2. Not Working properly
    By Tejas Sanap in forum C Programming
    Replies: 7
    Last Post: 05-10-2011, 06:52 AM
  3. exit loop not working properly
    By melodia in forum C Programming
    Replies: 3
    Last Post: 11-21-2010, 06:04 PM
  4. tic tac toe not working properly
    By h_howee in forum Game Programming
    Replies: 2
    Last Post: 01-01-2006, 01:59 AM
  5. why isn't my loop working properly?
    By orion- in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:23 PM