declare

A declaration statement introduces a new local variable.

Syntax

Every variable has a type, which defines the kind of values it can store. You can explicitly specify the type by providing a <variable type> after the as keyword.

The initial value of the variable can be set by using an initialization expression (<variable value>) following the being keyword. If no type is specified, the compiler automatically infers the variable type from this initialization expression.

Optionally, you can also define a <default value> using the defaulting to keyword. This default value is used whenever no value is provided or when the provided value is null.

Declare with an initial value

Declares a variable and initializes it with a value. The variable type is inferred from the value.

Syntax
declare 'variable name' being <variable value> ;
Example
declare x being 10 ;
Expected output
x is a number with the value 10.

Declare with an explicit type

Declares a variable with a specified type. The variable is initialized to null by default.

Syntax
declare 'variable name' as <variable type> ;
Example
declare text as a string ;
Expected output
text is a string initialized to null.

Declare with a type and an initial value

Declares a variable with both an explicit type and an initial value.

Syntax
declare 'variable name' as <variable type> being <variable value> ;
Example
declare text as a string being "John Doe" ;
Expected output
text is a string initialized to "John Doe".

Declare with a default value

Declares a variable with a type, an initial value, and a fallback default value. The default value is used if the initial value is null or not provided.

Syntax
declare 'variable name' as <variable type> being <variable value> defaulting to <default value> ;
Example
declare text as a string being result defaulting to "John Doe" ;
Expected output
text is a string initialized to the value of result if result is not null. Otherwise, it is set to "John Doe".