HyperMath

nil Values

nil Values

Previous topic Next topic No expanding text in this topic  

nil Values

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

nil is a special value which means a variable has no value.  For example:

> x = 2.5

> print(x)

2.5

> x = nil

> print(x)

nil

You can test to see if a variable exists by checking whether its value is nil.

> print(x == nil)

True

 

if (x == nil){

 print("x is nil")

} else {

 print("x is not nil")

}

> x is nil

 

> x = 7

> print(x == nil)

false

> print(x)

7

nil cannot be used in any math operation. An error message will be displayed if used in a math operation.

> x = nil

> y = 7

> z = x+y

> [string "z = x+y"]:1: attempt to perform arithmetic on a nil value