While Statement
The jabasamma statement is used to repeat a block of code while a condition is true.
Syntax
jabasamma(expression) Basic While Loop
A simple while loop that counts from 1 to 5:
purna i;
i = 1;
jabasamma(i <= 5) {
bhana(i);
i = i + 1;
}
:) Output: 1 2 3 4 5While Loop with Condition
A while loop that continues until a condition is met:
purna sum;
purna num;
sum = 0;
num = 1;
jabasamma(sum < 100) {
sum = sum + num;
num = num + 1;
bhana("Sum: ");
bhana(sum);
}Infinite Loop
You can create an infinite loop using thik as the condition. Be careful with infinite loops, as they can cause your program to hang.
purna i;
i = 1;
jabasamma(thik) {
bhana(i);
i = i + 1;
yadi(i > 10) {
:) Exit the loop when i > 10
:) (Note: Lipi doesn't have a break statement in this documentation)
}
}Important Notes
- The condition is checked before each iteration of the loop.
- If the condition is initially false, the loop body will not execute at all.
- Make sure to update the condition inside the loop to avoid infinite loops.
Next Steps
Now that you understand while statements in Lipi, you can learn more about: