Variables
Variables in EasyBite are named containers used to store data. They can hold different data types such as strings, numbers, booleans, arrays, and more. Variables must be declared before use using the declare
keyword.
Declaring a Variable
To declare a variable in EasyBite, use the declare
keyword followed by the variable name:
declare username
Declaring Multiple Variables
You can declare multiple variables in the same line, separated by commas:
declare username, password, loggedIn
Declaring Variables and Arrays Together
EasyBite allows declaring regular variables and arrays in the same declare
statement:
declare username, users[], scores[5]
Assigning a Value
To assign a value to a variable, you can use the set
keyword:
set username to "admin"
Alternatively, EasyBite also supports direct assignment without the set
keyword:
username to "admin"
Reassigning Values
Once declared, you can reassign a value to a variable directly, even without the set
keyword:
declare score
set score to 10
score to 20
Variable Naming Rules
- A variable name must start with a letter.
- It can include letters, digits, and underscores.
- It must not be a keyword or reserved word.
- Variable names are case-insensitive.
Arrays
EasyBite supports arrays (fixed and dynamic length) for storing lists of values.
Declaring an Array
To declare an array variable, specify the size or leave it empty for a dynamic array:
declare numbers[10] // Fixed length of 10
declare names[] // Dynamic length
Assigning Array Values
You can assign values to arrays using square brackets:
numbers to [1, 2, 3, 4, 5]
names to ["Ali", "Zara", "Umar"]
Accessing Array Elements
Array indices start at 0:
show(names[0]) // Outputs: Ali
Updating Array Elements
You can update specific elements by their index:
names[1] to "Fatima"
Null Values
If a variable is declared but not assigned, it holds the value null
:
declare temp
show(temp) // Output: null
temp to null // Explicitly assigning null
Dynamic Typing
A variable can change its type based on assigned values:
declare data
data to 42
data to "forty-two"
data to true
Summary Table
Syntax | Purpose |
---|---|
declare varName | Declares a variable |
declare var1, var2, var3 | Declares multiple variables in one line |
declare var1, arr1[], arr2[5] | Declares variables and arrays together |
set varName to value | Assigns a value |
varName to value | Reassigns a new value |
declare array[n] | Declares a fixed-length array |
declare array[] | Declares a dynamic-length array |
array[index] | Access or modify array elements |
null | Represents an uninitialized or empty value |