"Manalap " <email@example.com> wrote in message news:firstname.lastname@example.org... > I encountered a very strange problem when using if else structure. > > Simply put, this problem is like the following. > > If I code > > if x >3 > .... > elseif x<=3 > .... > end > > > then I get a wrong result, but where as if I code > > if x>3 > ... > else > ... > end > > > then I get the correct result that I expected through symbolic reasoning. > > Aren't these two the same thing?
"An evaluated expression is true when the result is nonempty and contains ***all*** nonzero elements (logical or real numeric). Otherwise, the expression is false." [Emphasis added.]
In the first case, neither the IF condition nor the ELSEIF condition are satisfied for the x I gave above, since some elements are greater than 3 and some are less than or equal to 3. In the second case, the IF condition is not true but the ELSE is unconditional; it WILL execute if the IF does not.