Skip to main content

Language Reference

Cpyte is a statically-typed, compiled language with Python-inspired syntax.

Variables

# Type inference
x = 42
name = "hello"
pi = 3.14

# Explicit types
int count = 10
int64 large = 9223372036854775807
float ratio = 0.5
str text = "world"
bool flag = true

Operators

# Arithmetic
result = 10 + 5 * 2
power = 2 ** 10
div = 20 // 4 # integer division
mod = 17 % 5

# Comparison
if x == y:
print("equal")
if x != y:
print("not equal")

# Logical
if a and b:
print("both true")
if not flag:
print("false")

# Bitwise
mask = 0xFF & value
shifted = x << 2

Control Flow

If/Else

if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("C")

Switch

switch day:
case 1:
print("Monday")
case 2:
print("Tuesday")
default:
print("Other")

Loops

# While
while i < 10:
print(i)
i += 1

# For
for item in collection:
print(item)

Jump Statements

while true:
if done:
break

for i in range(10):
if i % 2 == 0:
continue
print(i)