## why does false || false = true ???

### why does false || false = true ???

Here's one that's confusing me...  While solving a problem in
a programing book I came up with this, but I don't understand
why it works.  (I just kept trying things until I got the right

i=1
while [ \$((\$i%3)) -ne 2 ] || [ \$((\$i%5)) -ne 3 ] || [ \$((\$i%7)) -ne 4 ]
do
let i=\$i+1
done
echo The Number is \${i}.

The part that is confusing to me is the while condition.
I am "OR"ing 3 test conditions.  When they are all false,
the while loop is exited.

It seems to work like,
when [ false OR false OR false ]
then
exit loop
done

I'd think it would work like this,
when [ true AND true AND true ]
then
exit loop
done

Here is the last 10 lines of a trace on the loop:

+ let i=50+1
+ [ 0 -ne 2 ]
+ let i=51+1
+ [ 1 -ne 2 ]
+ let i=52+1
+ [ 2 -ne 2 ]                   # false condition
+ [ 3 -ne 3 ]                   # false condition
+ [ 4 -ne 4 ]                   # false condition
+ echo The Number is 53.
The Number is 53.

Can anyone explain why OR'ing false statements works this way?

p.s. this isn't for a class or anything, so I don't have a

p.p.s.
Here is the original problem:
Write a program to find the smallest positive integer n
which corresponds to the following conditions:
n / 3 = integer x and remainder 2
n / 5 = integer y and remainder 3
n / 3 = integer z and remainder 4

--
Randall W. Hron
Roswell, GA

uunet!gatech!kd4nc!vdbsan!willard!hrandoz!hronr

### why does false || false = true ???

Quote:>Here's one that's confusing me...  While solving a problem in a programing
>book I came up with this, but I don't understand why it works.  (I just kept
>trying things until I got the right answer)
>i=1
>while [ \$((\$i%3)) -ne 2 ] || [ \$((\$i%5)) -ne 3 ] || [ \$((\$i%7)) -ne 4 ]
>do
>    let i=\$i+1
>done
>echo The Number is \${i}.
>The part that is confusing to me is the while condition.  I am "OR"ing 3 test
>conditions.  When they are all false, the while loop is exited.
>It seems to work like,
>when [ false OR false OR false ]
>then
>    exit loop
>done

No, it's like this:

when [ false AND false AND false ]
then
exit loop
done

That's because of simple Boolean algebra:

NOT(a OR b) = (NOT a) AND (NOT b).

Your `when' statement uses this incorrect rule:

NOT(a OR b) = (NOT a) OR (NOT b)

Michael.

### why does false || false = true ???

Quote:>Can anyone explain why OR'ing false statements works this way?
>Here is the original problem:
>Write a program to find the smallest positive integer n
>which corresponds to the following conditions:
>n / 3 = integer x and remainder 2
>n / 5 = integer y and remainder 3
>n / 3 = integer z and remainder 4

Let me save you some time right from the beginning!

if this is the original problem, then your program will run forever
because there is no solution!

the way I see it we can rephrase your problem like
so

n = 3x+2
n = 5y+4
n = 3z+4

which means 3x+2 = 3z+4

rearranging gives 3x = 3z + 2
dividing by 3 gives x = z +2/3

You tell me which integer x equals another integer z + 2/3

Besides this is nothing more than a simultaneous equation problem and does
not require a loop to begin with!  Solve the equations in terms of one
variable and choose 1 as you lowest integer for that variable and figure
out what the other variable would be.

Joe Carl

You must have misquoted the problem
--
ShadowMaster "If you ever drop your watch in a pool of molten lava, let it go,
'cause man it's gone"          Saturday Nigh Live "Deep Thoughts"

### why does false || false = true ???

Quote:

>Here's one that's confusing me...  While solving a problem in
>a programing book I came up with this, but I don't understand
>why it works.  (I just kept trying things until I got the right

>i=1
>while [ \$((\$i%3)) -ne 2 ] || [ \$((\$i%5)) -ne 3 ] || [ \$((\$i%7)) -ne 4 ]
>do
>    let i=\$i+1
>done
>echo The Number is \${i}.

>The part that is confusing to me is the while condition.
>I am "OR"ing 3 test conditions.  When they are all false,
>the while loop is exited.

No you're not.  You're executing the first test, and if it returns
false then you're executing the second, which if false executes the
third.  If you get to the third, then its outcome determines when
you exit the loop.

|| isn't a boolean arithmetic operator, it is a conditional execution
operator.  It executes the antecedent only when the precedent returns a
false exit code.

-r

### why does false || false = true ???

>|| isn't a boolean arithmetic operator, it is a conditional execution
>operator.  It executes the antecedent only when the precedent returns a

^^^^^^^^^^

Quote:>false exit code.

Whoops!  Make that "conclusion."

-r

In the stupid /usr/ports/editors/staroffice52/Makefile there is
a section which goes:
=====================
.if defined(WITH_CDROM)
.if !exists(\${CD_MOUNTPT}/linux/office52/setup)

.endif
.endif
======================
Despite the fact that when I do a
"ls -l /cdrom/linux/office52/setup" I get
-r-xr-xr-x  1 rot wheel 66936 May 12  2000 /cdrom/linux/office52/setup

The Makefile is still saying there is no setup file!
Can anyone suggest why?

----------
A nations human decency can be measured by the
number of its citizens who phone or write their government
to improve the world.
http://www.fandom.net/~daeron/Cyclo/Brainia/8635.html