[BUG] or maybe not

Pendrush

Well-Known Member
Licensed User
Longtime User
B4X:
Dim a As Int : a = 1
Dim b As Int : b = 1
Dim c As Int : c = 1

Do While a = b AND a = c AND b = c
   b = Rnd(1,4)
   c = Rnd(1,4)
Loop
Log(a & "-" & b & "-" & c)

and im getting these results

B4X:
1-2-2
1-1-2
1-1-3
1-3-2
1-1-2
1-1-3
1-1-3
1-3-2
1-2-3
1-3-1
1-2-2

but when using Do Until and change line to

B4X:
Do Until a <> b AND a <> c AND b <> c
im getting expected results a, b, c are not same with each other.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no bug.

Lets assume that a = 1, b = 1 and c = 2.
The conditions:
1. a = b AND a = c AND b = c => Result is FALSE (because b is not equal to c)
2. a <> b AND a <> c AND b <> c => Result is FALSE (because a equals to b)

So the Do While <condition 1> will exit and the Do Until <condition 2> will not exit.

You can read about boolean algebra here: De Morgan's laws - Wikipedia, the free encyclopedia
 
Top