-
Notifications
You must be signed in to change notification settings - Fork 0
Functions
Julius Paffrath edited this page Feb 18, 2025
·
5 revisions
A function in jask consists of a name and optional parameters:
; no parameters
myFunction()
; one parameter
myFunction(myParameter)
; two parameters, separated by a colon
myFunction(param1:param2)Creating own functions in jask is very easy:
function myFunction(param1:param2)
printLine("This is the first parameter: ":param1)
printLine("And this is the second: ":param2)
endBe aware: When using parameters, jask uses passing by value not by reference. Learn more about this topic here.
Functions can return nothing, any type of data or calculations:
function myFunc()
print("Functions are great!")
end
function returnString(str)
return str
end
function plus(num1:num2)
return num1 plus num2
endIf you want to call a function several times, you can do this:
run i to 10 with i plus 1
printLine("i is ":i)
endrunOr you can use a while loop:
while val equals TRUE
printLine("val is TRUE!")
endrunIf the body of the loop consists only of one statement, you can use the call operator instead:
call printLine("Hello!") 100 timesThis will call the function 100 times and is more readable.
- Home
- Getting started
- Control flow
- Functions
- Passing by value
- List variables in jask
- Dictionary variables in jask
- Structs in jask
- Convert variables
- Internal Functions
- The access operator
- Callbacks in jask
- Modules
- Internal Modules
- The jask standard library jcore
- Using CMD arguments in jask
- Nested function calls
- Functions inside functions!
- Modules inside functions!
- Performance comparison of loops