Skip to content
Nicolas Maitre edited this page Jan 20, 2021 · 1 revision

Syntax basics

ProgCraft programs are written in vanilla Ruby so most features are available. Ruby documentation

comments

Comments start with #

# This is a comments

variable

# Number
my_var_number = 12
# Text
my_var_text = "It's a text"

# Array
my_var_array = [value1, value2, value3, ...]

if / elsif / else

if condition
    # code
elsif condition
    # code
else
    # code
end

for

elements = ["M.Favre", "M.Chavey", "M.Carrel"]
for element in elements
    # code
end

while

while condition
    # code
end
# or 
begin
    # code
end while condition

switch

my_var_number = 12
case my_var_number
    when my_var_number <= 10
        # code
    when my_var_number > 10 && my_var_number < 15
        # code
    when my_var_number == 42
        # code
    else
        # cdoe
end

function

def myfunction(parameter1, parameter2)
    #code
end
# and call it
myfunction("parameter1", "parameter2")

Clone this wiki locally