Thread: if problem

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    Pozarevac, Yugoslavia
    Posts
    24
    Rep Power
    0

    if problem


    i write this code:

    if ((($first != "+") OR ($first != "-")) AND (($last != "+") OR ($last != "-"))) {

    .....

    }


    but not work properly...why? and can i write it in some other (better) way
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,640
    Rep Power
    4247
    I think you really meant
    Code:
    if ((($first != "+") AND ($first != "-")) AND (($last != "+") AND ($last != "-"))) {
     ....
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    Pozarevac, Yugoslavia
    Posts
    24
    Rep Power
    0
    $first is first character of string, and $last is last character of string... i mean that first character of string must not be "+" or "-" and last character must not be "+" or "-"....how do i write it?
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,640
    Rep Power
    4247
    Yep, the statement that I posted above would work. Also you could remove some parenthesis if you like
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    Pozarevac, Yugoslavia
    Posts
    24
    Rep Power
    0
    thnanx, works! (but, i do not understand why don't work my algorithm...i write like i say my if clause)

    could i write it in some other, better (algorithm) way?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    You are checking to see if the first character is not '+' or not '-'. That will always evaluate to true since it has to not be at least one of them. The same holds true for the last character. Scorpions version checks to make sure that both the first and last characters are not '+' or '-'.
  12. #7
  13. php-oriented object
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    0x9832053
    Posts
    173
    Rep Power
    14
    PHP Code:
    if (($first!='+' OR $first!='-') AND ($last!='+' OR $last!='-')) 
    excuse me for the php code, but it gives some syntax hilight to the thing above.
    hope this helps
  14. #8
  15. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    tank, as per Scorpions code above, they all need to be 'AND' conditions, not 'OR'.
  16. #9
  17. php-oriented object
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    0x9832053
    Posts
    173
    Rep Power
    14
    wops...that's true! sorry
    well....too late here...gotta go to bed now

IMN logo majestic logo threadwatch logo seochat tools logo