Sebastian Hungerecker
2/14/2008 10:19:00 PM
dare ruby wrote:
> but it works fine when the condition changes like,
>
> =C2=A0 =C2=A0 =C2=A0if @character =3D=3D 'R' =C2=A0|| @character =3D=3D '=
r'
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 raise " Expected 'R' after 'E' in version Dec=
laration"
> =C2=A0 =C2=A0 =C2=A0 end
Here you are saying: if character is 'R' or if it is 'r'. This condition=20
obviously can be true (if it is one of 'r' or 'R') or false (if it's=20
something else).
Previously you were saying: if character is something other than 'R' or it =
is=20
something other than 'r'. This will, as Paul pointed out, always be true.=20
Just think about: If character is 'R' than the first part won't be true ('R=
'=20
is not different from 'R'), but the second part will (because 'R' is=20
different from 'r'). If it is 'r', it's the other way around. And since the=
=20
whole expression is true when (at least) one of the parts is true (that's=20
what "or" means), it's always true. What you want is: !(@c =3D=3D 'R' || @c=
=3D=3D'r')=20
which is equivalent @c !=3D 'R' && @c !=3D 'r'. Note how here you have && i=
nstead=20
of ||. That's the law of DeMorgan that Paul mentioned:
!(a && b) <-> !a || !b
!(a || b) <-> !a && !b
HTH,
Sebastian
=2D-=20
Jabber: sepp2k@jabber.org
ICQ: 205544826