Thread: while loop problem

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    13

    while loop problem

    I'm trying to create a while loop with an 'or'.

    The program runs fine without the 'or' but when I add it, the program outputs nothing. Here is the loop in question:

    Code:
    while ( (sentence[pos] != ' ') || (sentence[pos] != '.') )
    		{
    		   count++;
    		   pos++;
    		}
    I want it to execute the loop while sentence[pos] is not a space, or a period. When I add in then part about not being a period, it seems to kill the loop. Is this improper syntax?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    It's all the english

    You want to execute the loop while sentence[pos] is not a space and not a period.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    13
    Wow, don't I feel stupid now. Thanks a lot, I think thats the second or third time you've helped me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  3. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  4. Loop problem
    By Tesnik in forum C++ Programming
    Replies: 29
    Last Post: 08-23-2007, 10:24 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM