Pendrush Well-Known Member Licensed User Longtime User Nov 13, 2012 #1 Code: 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 Code: 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 Code: Do Until a <> b AND a <> c AND b <> c im getting expected results a, b, c are not same with each other.
Code: 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 Code: 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 Code: Do Until a <> b AND a <> c AND b <> c im getting expected results a, b, c are not same with each other.
thedesolatesoul Expert Licensed User Longtime User Nov 13, 2012 #2 It is not a bug. This is what your condition states: Code: Do While a = b AND a = c AND b = c This is not equivalent to a<>b<>c If you want all three to be different then use: Code: Do While a = b OR a = c OR b = c So if any one of them are similar it keeps generating new numbers.
It is not a bug. This is what your condition states: Code: Do While a = b AND a = c AND b = c This is not equivalent to a<>b<>c If you want all three to be different then use: Code: Do While a = b OR a = c OR b = c So if any one of them are similar it keeps generating new numbers.
agraham Expert Licensed User Longtime User Nov 13, 2012 #3 Elementary Boolean transformation Code: Do While a = b AND a = c AND b = c becomes Code: Do Until a <> b OR a <> c OR b <> c
Elementary Boolean transformation Code: Do While a = b AND a = c AND b = c becomes Code: Do Until a <> b OR a <> c OR b <> c
Erel B4X founder Staff member Licensed User Longtime User Nov 13, 2012 #4 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
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
thedesolatesoul Expert Licensed User Longtime User Nov 13, 2012 #7 Wow, this must be the fastest posting thread!