Why it doesnt work?
Why it doesnt work?
(OP)
why this code doesnt work?? if i put k += 1 it gives the correct anwer k = 6
*Whats going on?
Sub Main()
Dim m As Double(,) = {{6, 2, 6}, {1, 3, 7}}
Dim k As Double
Dim A0 As Double
Do Until A0 = 1.0
k += 0.1
A0 = m(0, 0) / k
Loop
Console.WriteLine("k is " & k)
*Whats going on?
Sub Main()
Dim m As Double(,) = {{6, 2, 6}, {1, 3, 7}}
Dim k As Double
Dim A0 As Double
Do Until A0 = 1.0
k += 0.1
A0 = m(0, 0) / k
Loop
Console.WriteLine("k is " & k)





RE: Why it doesnt work?
Dim m As Double(,) = {{6.0, 2.0, 6.0}, {1.0, 3.0, 7.0}}
RE: Why it doesnt work?
2) The exit condition for loops should never depend on comparing floating point numbers. Due to how the computer stores numbers you may end up with A0=1.0000000001; which does not equal 1.0 and the loop would keep going.
It looks like you want to normalize an array. In this case k=1/A0, no need to loop to find the value of k.