 ### Data Types and Variables

Dinfio Documentation

###### Data Types

Dinfio provides two data types, known as `Primitive` and `Reference` data types. `Primitive`s are data types that store simple values, including numbers, strings, and booleans. `Reference`s are data types that store arrays and objects.

A number, string, boolean, array, and object can be stored in a variable. Dinfio is dynamically-typed language, so a variable can store any data type without providing type annotation. But, you can still provide annotation to an object to help IDE (i.e. Dinfio IDE[?]) builds code completion list and code hint.

###### Primitive Data Types: Number, String, and Boolean

1. A number can be written in decimal, hexadecimal, and binary base format. `23` is an example of decimal base, `0x6F1E0A` is an example of hexadecimal base, and `10111b` is an example of binary base:

``````a = 23       ' Decimal base
b = 14.2     ' Decimal base with floating point
c = -120     ' Decimal base with minus
d = 0x6E     ' Hexadecimal base
e = 10111b   ' Binary base
``````

2. String is a sequence of characters surrounded by double quotation marks ("). `"My name is Clara"` is an example of string.

``````name = "Clara"
writeln("Hello, my name is " & name)   ' Output: Hello, my name is Clara
``````

3. Boolean is a data type that has only one of two possible values: `true` and `false`.

``````a = true
b = false
c = false

d = !a       ' d is false
e = a && b   ' e is false
f = a || c   ' f is true
``````

###### Variable Scope

There are two types of declaring variable: globally and locally. A global variable can be accessed anywhere in the code. You can declare a global variable using keyword `global`:

``````start
global a = 10

do_something()

writeln(a)   ' a is now 20
writeln(b)   ' b is 100
stop

function do_something()
a = 20
global b = 100
stop``````

And a local variable can be only accessed in function block. You can declare a local variable using keyword `var`:

``````start
global a = 10

do_something()
do_something_again()

writeln(a)   ' a is still 10
stop

function do_something()
var a
a = 20
stop

function do_something_again()
var a
a = 40
stop``````

If you declare a local variable in the `Main Statements` block, it acts as global variable:

``````start
var a = 10

do_something()
writeln(a)   ' a is now 20, because a is global variable
stop

function do_something()
a = 20
stop``````

 ← Code Structure Index Operators →

Documentation version: 1.0.09. Updated on: 17 April 2021.
Dinfio is designed and written by Muhammad Faruq Nuruddinsyah. Copyright © 2014-2021. All rights reserved.