Variables

define a new variable with v

Use v to declare a variable. You must give it a type, a name, and a value.

syntax
v type name = value
examples
v int    age    = 20          ~ whole number
v double price  = 9.99        ~ decimal number
v bool   done   = false       ~ true or false
v string name   = Ahmed       ~ text
TypeWhat it stores
intWhole numbers — 0, 5, -3, 100
doubleDecimal numbers — 3.14, 0.5, -1.8
booltrue or false only
stringAny text — name, word, sentence

Print

write to the screen with print

print shows a value, a variable, a quoted string, or the result of a math expression.

syntax
print value_or_expression
examples
print 42                    ~ prints: 42
print age                   ~ prints the value of age
print "Hello World"         ~ prints: Hello World
print 5 + 3                ~ prints: 8
print age + 1              ~ prints age + 1
output
42
20
Hello World
8
21

Reassign

change a variable's value with n v

Once a variable is declared, use n v to give it a new value. You can use its current value in the expression on the right.

syntax
n v name = expression
examples
v int x = 10
n v x = x + 5    ~ x is now 15
n v x = x * 2    ~ x is now 30
n v x = 0         ~ x is now 0
print x            0

User Input

read from the keyboard with r

r pauses the program and waits for the user to type something. The variable must be declared first — APL uses its type to convert the input correctly.

syntax
r name
example
v int age = 0      ~ declare first
r age              ~ prompt appears: user types 25
print age          25

If / Else

run code only when a condition is true

Wrap code in { } — APL runs it only if the condition is true. Add else { } to handle the false case.

syntax
if name condition value {
  ~ runs when true
}
else {
  ~ runs when false
}
example
v int score = 85
if score > 60 {
  print "Pass"
}
else {
  print "Fail"
}
output
Pass

Supported comparison operators inside if:

> greater than < less than A= equals != not equal >= greater or equal <= less or equal

Loop

repeat code while a condition is true with Loop

Loop keeps running the block inside { } as long as the condition holds. Don't forget to change the variable inside — otherwise it loops forever!

syntax
Loop name condition value {
  ~ repeats while true
}
example — count 1 to 5
v int x = 1
Loop x < 6 {
  print x
  n v x = x + 1
}
output
1
2
3
4
5

Functions

define once, call anywhere with func and call

A func bundles lines of code under a name so you can reuse them. Use call to run it whenever you need it.

syntax
func name {
  ~ your code here
}

call name
example
func greet {
  print "Hello from APL!"
  print "Welcome."
}

call greet
call greet   ~ call it as many times as you want
output
Hello from APL!
Welcome.
Hello from APL!
Welcome.

Operators

math and comparison symbols APL understands

math
SymbolOperation
+addition
-subtraction
*multiplication
/integer division (no decimals)
comparison — used in if and Loop
SymbolMeaning
>greater than
<less than
A=equal to
!=not equal to
>=greater than or equal
<=less than or equal

Types

the four data types APL supports

TypeExample valueWhat it means
int5, -3, 100Whole integer number
double3.14, 0.5Number with decimal point
booltrue, falseBoolean — yes or no
stringAhmed, HelloPlain text (no quotes needed)

Cheat Sheet

the whole language on one board

~ ─── Variables ───────────────────
v int    x     = 5
v double pi    = 3.14
v bool   done  = false
v string name  = Ahmed

~ ─── Print ───────────────────────
print x
print "Hello World"
print 5 + x

~ ─── Reassign ────────────────────
n v x = x + 1

~ ─── Input ───────────────────────
r x

~ ─── If / Else ───────────────────
if x > 10 {
  print "big"
}
else {
  print "small"
}

~ ─── Loop ────────────────────────
Loop x < 10 {
  print x
  n v x = x + 1
}

~ ─── Functions ───────────────────
func greet {
  print "Hello!"
}
call greet
▶ Run it yourself