Conditions
- An if condition must have type bool; Nenu has no truthy conversion.
- Use else if for ordered alternatives and else for the final fallback path.
- Keep each branch responsible for one decision and move reusable calculations outside it.
Basic Syntax
1if expense.amount > 0 {2 valid = true3}45if expense.status == ExpenseStatus.Settled {6 label = "Settled"7} else {8 label = "Open"9}The expression between if and { must resolve to bool. Parentheses around the condition are unnecessary. The braces are required even for one statement.
Ordered Alternatives
1if balance > 0 {2 label = "Is owed money"3} else if balance < 0 {4 label = "Owes money"5} else {6 label = "Even"7}Branches are checked from top to bottom. The first true condition runs, and later alternatives are skipped. Put the narrowest or highest-priority case first.
Combining Conditions
1can_settle = amount > 0 and balance < 02needs_attention = amount <= 0 or title == ""34if can_settle and expense.status != ExpenseStatus.Settled {5 ready = true6}| Operator | Meaning | Operand type |
|---|---|---|
and | Both conditions are true. | bool |
or | At least one condition is true. | bool |
! | Invert one condition. | bool |
| Comparison operators | Compare compatible values. | Depends on the compared type. |
Ternary Expressions
1string label = expense.status == ExpenseStatus.Settled : "Settled" | "Open"2number signed_amount = balance < 0 : -balance | balanceUse condition : then_value | else_value when one boolean decision produces one value. The condition must be bool, and both result expressions must have compatible types. Nenu permits at most two nested ternary levels; use an if statement or helper function for deeper branching.
Room Expense Example
1if request.amount <= 0 {2 throw BadRequest("Amount must be greater than zero")3}45if request.title == "" {6 throw BadRequest("Title is required")7}89Expense expense = Expense {10 room_id: room.id11 payer12 title: request.title13 amount: request.amount14 note: ?15 receipt: ?16 status: ExpenseStatus.Open17}1819save(expense)20return Response { expense }The early branches stop invalid requests before construction or persistence. The successful path stays unindented and easy to read.
Common Mistakes
| Wrong | Correct | Reason |
|---|---|---|
if amount { ... } | if amount > 0 { ... } | Numbers are not truthy. |
if note { ... } | with note { ... } | Optionals require presence proof. |
elif | else if | Nenu uses two keywords. |
if condition then | if condition { ... } | There is no then keyword. |
condition ? a : b | condition : a | b | Nenu uses colon and pipe for a ternary expression. |
