Helpful Information
 
 
Category: Software Design
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

I think you really meant


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

$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?

Yep, the statement that I posted above would work. Also you could remove some parenthesis if you like :)

:) 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?

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 '-'.

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 :)

tank, as per Scorpions code above, they all need to be 'AND' conditions, not 'OR'.

wops...that's true! sorry :(
well....too late here...gotta go to bed now :D










privacy (GDPR)