Thread: complicates loops

  1. #16
    ___
    Join Date
    Jun 2003
    Posts
    806
    Originally posted by Sang-drax
    You know,
    Code:
    if (((letter >= 'A') && (letter <= 'Z'))  ||
        ((letter >= 'a') && (letter <= 'z')))
    can be written as
    Code:
    if (letter >= 'A' && letter <= 'Z'  ||
        letter >= 'a' && letter <= 'z')
    IMO, the second way looks better.


    Oh thank you so much. It is allot easier to do that than the other way for sure. One question. Why does the other one have so many of those when the second one works fine with only 2?
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  2. #17
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Either the author of the book is trying to show the seperate comparisons or it is a badly written book.

  3. #18
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Probably to make it clear which expressions are to be evaluated first. If you don't want to take the time to see which expressions are evaluated first you can simply put in parentheses. In this case it works without them because inequeality relational (<=, <...) have precedence, followed by logical AND and finally logical OR
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #19
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>It is allot easier to do that than the other way for sure.
    But it still doesn't guarantee what's been entered is a letter (see my previous post).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  2. For/Next Loops...adding 10 numbers...
    By IanelarAzure in forum C++ Programming
    Replies: 5
    Last Post: 09-12-2002, 12:02 PM
  3. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  4. for loops in C
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-15-2001, 05:09 PM
  5. exiting loops with ease?
    By KingRuss in forum Game Programming
    Replies: 3
    Last Post: 09-24-2001, 08:46 PM