Quick start
Example: Iterative Factorial
This example highlights LaadleLang's jabtak (while) loops, variable mutation, and conditional breaking (bas and chal) inside an iterative sequence.
The Code
// A function that calculates a factorial iteratively without recursion
kaam calculate_factorial(n) toh
agar n < 0 toh
bol "Factorials are only for non-negative numbers!"
wapas
laadle result hai 1
laadle current hai n
jabtak current > 1 toh
result hai result * current
current hai current - 1
wapas result
// Output the sequence
laadle num hai 5
bol "Factorial of " + num + " is:"
bol calculate_factorial(num)What's Happening?
- Variables & Reassignment: We declare variables using
laadle. Inside thejabtakloop, we simply omit thelaadlekeyword to mutate the existingresultandcurrentvariables rather than declaring new ones. - Loop Condition: The
jabtak current > 1 tohloop continually runs its nested block until the condition becomes falsy. - Execution Guarding: The
agar n < 0 tohcode block acts as a safety barrier. If triggered, it prints a warning and invokes a barewapasto break out directly without iterating or causing an infinite loop.