Home

Asserting an Expression

   

Description

Consider the following code that provides a radius of a circle and calculates the diameter:

let radius = 25.08
let diameter = radius * 2.00

 

 

Here is another version of the program with a negative value for the radius:

let radius = -25.08
let diameter = radius * 2.00

The F# language provides a special function used to evaluate an expression. The function is named assert and its syntax is:

assert expression

The expression must evaluate to a true or false result. Here is an example:

let radius = -25.08
let diameter = radius * 2.00

assert (radius > 0.00)

When the assert() function is called, if it returns false, the compiler displays an error dialog box and stops. Here is an example:

Asserting an Expression

If the function returns true, the program proceeds normally.

     
     
 

Home Copyright © 2015, FunctionX Home