Control Flow & Pattern Matching
Djazair provides clear branching constructs: if-elif-else statements, concise ternary expressions, and structural match-case pattern matching.
If, Elif, Else
djazair
let score = 85
if score >= 90
print("Grade: Excellent")
elif score >= 75
print("Grade: Very Good")
elif score >= 50
print("Grade: Pass")
else
print("Grade: Retake")
end
Ternary Expression
Djazair offers an inline ternary syntax for assigning values based on a condition:
djazair
let age = 20
let status = if age >= 18 ? "Adult" else "Minor"
print("User status: ${status}") # => User status: Adult
Pattern Matching (match-case)
The match construct provides structured multi-way branching, supporting multiple values per case and fallback defaults:
djazair
let httpStatus = 404
match httpStatus
case 200, 201, 204
print("Success")
case 301, 302
print("Redirect")
case 400, 401, 403, 404
print("Client Error: ${httpStatus}")
case 500, 502, 503
print("Server Error")
default
print("Unknown Status Code")
end
# => Client Error: 404