-
Notifications
You must be signed in to change notification settings - Fork 0
Syntax
Contrary to many other programming languages, in Kode, commands must never end with a semicolon.
Printing hello world in Kode is very straightforward: print("Hello world!")
Comments are bits of text embedded to code with the function of describing the code and/or annotating remarks. Comments must be written on an empty line or at the end of a line. To indicate the beginning of a comment, a pound sign # must be used first. For example,
# This is a comment in Kode
val myVariable = "Hello World!" # this is another comment
Just like variables, arrays can be created with the keyword val, or with specific type. If an array will only contain one type of values, it is possible to initialize it with int[], float[], bool[] or string[].
val arrayOfValues = [1, "Kode", true, 0.2]
int[] arrayOfInts = [1, 2, 3, 4]
# These will cause errors
float[] arrayOfFloats = [1.4, 1.5, "hello"]
string[] arrayOfStrings = "my string is not in an array"
To add values to an array, the append(array, element) function can be used. Append returns the new array and does not modify the original, it must be assigned to it instead.
val myArray = [1, 2, "Fred", "Eduard"]
myArray = append(myArray, "Kode")
After this, myArray contains [1, 2, "Fred", "Eduard", "Kode"]
val myArray = [1, 2, "Fred", "Eduard"]
append(myArray, "Kode")
After this, myArray contains [1, 2, "Fred", "Eduard"]
To remove values from an array, the truncate(array, index) function can be used. Just like append, truncate returns the modified array.
val myArray = [1, 2, "Fred", "Eduard"]
myArray = truncate(myArray, 0)
After this, myArray contains [2, "Fred", "Eduard"]
if myCondition
print("myCondition is true")
else
print("myCondition is false")
end if
if condition1 and condition2
print("Both conditions are true")
else if not condition1
print("condition1 is false")
else if condition1 or condition2
print("At least one condition is true")
else
print("This is getting confusing")
end if
In Kode, for loops do not have a built in counting variable. Instead, the user must set it up themselves. Here is an example of a for loop in Kode:
int i = 0
for i < 10
print(i)
i = i + 1
end for