Control Flow
Control Flow
Thagore supports if/else, while, for item in array, break, and continue. Conditions in if and while must be wrapped in parentheses.
if / else
func classify(n: i32) -> i32: if (n > 0): return 1 else: if (n < 0): return -1 else: return 0There is no elif keyword. Use else followed by another if for multiple branches.
Logical operators
and, or, and not are contextual keywords used inside conditions:
func check(x: i32, y: i32) -> i32: if ((x > 0) and (y > 0)): return 1 if ((x == 0) or (y == 0)): return 0 return -1func is_not_zero(x: i32) -> bool: return not (x == 0)Comparison operators
| Operator | Meaning |
|---|---|
== | Equal |
!= | Not equal |
< | Less than |
> | Greater than |
<= | Less than or equal |
>= | Greater than or equal |
and | Logical AND |
or | Logical OR |
not | Logical NOT |
while
func sum_to(n: i32) -> i32: let i: i32 = 0 let total: i32 = 0 while (i <= n): total = total + i i = i + 1 return totalThere is no ++ or --. Use i = i + 1.
for
for iterates over Array[T] values:
func sum_items(items: Array[i32]) -> i32: let total: i32 = 0 for item in items: total = total + item return totalThere is no numeric range syntax (0..10). Arrays usually come from runtime-backed functions such as io.read_ints or string.split.
break and continue
func bounded_sum(limit: i32) -> i32: let i: i32 = 0 let total: i32 = 0 while (i < limit): i = i + 1 if (i == 2): continue if (i == 5): break total = total + i return totalbreak and continue are contextual keywords — they are not reserved but are recognized by the parser in loop context.
Early return
func classify(value: i32) -> i32: if (value < 0): return 1 let adjusted: i32 = value + 1 if (adjusted > 10): return 2 return 0Arithmetic operators
| Operator | Meaning | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulo | a % b |