a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equal"}
end
when i run this code first condition satisfied ,instead of returning {:ok, "a"} tuple it starts executing next block of code, how can i stop the execution once first condition is met, and return result
To be more specific, there are no statements, everything returns something, including those lines, they just return it āupā (so the if returns it, but the if is not being assigned to anything so it vanishes).
Youāve got quite the eye for detail! And that brings up a great point: which one is more correct is going to depend on the actual requirements of the problem. Knowing multiple approaches to a problem can help choose the one that best matches the requirements.