HyperMath

if ... then ... else ... end

if ... then ... else ... end

Previous topic Next topic No expanding text in this topic  

if ... then ... else ... end

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

The statement if has the form:

if exp then

 block

elseif exp then

 block

…else

 block

end

For example, if ... then ... end:

 

> if 10>2 then print("bigger") end

bigger

if ... then ... else ... end:

 

> if 1>10 then

  print("bigger")

 else print("smaller")

 end

 smaller

if ... then ... elseif ... else ... end:

 

> number = 1; value = ""

The following has to be on a single line if typed in the command window; here it’s separated for clarity

> if number < 1 then

 value = "smaller than one";

elseif number==1 then

 value = "one";

else value = "bigger than one";

end

> print(value)

one

HyperMath supports another syntax for the if statement that is akin to the C-programming language:

if(exp)

{

block

}

elseif(exp)

{

block

}

else

{

block

}

The two formats cannot be mixed.

NoteIf exp is a matrix of real values, then the condition is true if all elements of the matrix are non-zero.