BCode Icon

BCode Full Documentation

Documentacion

Variables

Declare variables using the VAR keyword.

VAR name = "Bubu"
VAR number = 42
    

Functions

Define functions with FUN. Use RETURN to exit with a value.

FUN add(a, b)
    RETURN a + b
END

FUN greet(name)
    PRINT("Hello, " + name)
END
    

If Statements

Use IF, THEN, and ELSE for conditionals.

IF condition THEN
    PRINT("Condition is true")
END

IF condition <= 10 THEN
    PRINT("Less or equal to 10")
ELIF condition == 74
    PRINT("Equal to 74")
ELSE
    PRINT("Other value")
END
    

Printing

Use the PRINT() function to display text in the output.

PRINT("Hello, BCode!")
    

For Loops

Create loops with FOR and TO.

FOR i = 1 TO 10 THEN
    PRINT(i)
END
    

Comments

Add comments using the # symbol. They are ignored during execution.

# This is a comment in BCode
# I <3 BCODE
    

Joining Function

Example of a single-line function with the joining feature.

FUN oopify(prefix) -> prefix + "oop"
    

Overview Example

Here's a more complex example using various features of BCode:

# This is a very cool example

FUN oopify(prefix) -> prefix + "oop"

FUN join(elements, separator)
    VAR result = ""
    VAR len = LEN(elements)

    FOR i = 0 TO len THEN
        VAR result = result + elements/i
        IF i != len - 1 THEN 
            VAR result = result + separator
        END
    END

    RETURN result
END

FUN map(elements, func)
    VAR new_elements = []

    FOR i = 0 TO LEN(elements) THEN
        APPEND(new_elements, func(elements/i))
    END

    RETURN new_elements
END

PRINT("Greetings universe!")

FOR i = 0 TO 5 THEN
    PRINT(join(map(["l", "sp"], oopify), ", "))
END