While Loop
Learn how to repeat code while a condition stays true using `jotokkhon` in BornomalaScript.
While Loop
A while loop repeats code as long as a condition stays true.
In BornomalaScript, this style is written with jotokkhon and totokkhon.
Basic Example
Use jokhon (while):
dhoro x = 0
jotokkhon (x < 10) totokkhon {
jodi (x == 5) tahole {
thamo
}
lekho(x)
x++
}
This loop keeps running until x < 10 becomes false.
How It Works
The while loop checks the condition before each repetition.
That means:
- if the condition is true, the loop runs
- if the condition is false, the loop stops
Step-by-Step Breakdown
xstarts at 0- The condition checks whether
xis less than 10 - If yes, the body runs
lekho(x)prints the current valuex++increases the counter- The condition is checked again
Why Use a While Loop?
While loops are helpful when:
- you do not know the exact number of repetitions in advance
- you want to keep repeating until something changes
- you are waiting for a condition to become false
Important Note
Always make sure the value in the condition changes inside the loop.
If it never changes, the loop may keep running forever.
Try These Variations
Practice with different conditions:
dhoro count = 1
jotokkhon (count <= 5) totokkhon {
lekho(count)
count++
}
dhoro temp = 10
jotokkhon (temp > 0) totokkhon {
lekho(temp)
temp--
}
dhoro done = mittha
jotokkhon (done == mittha) totokkhon {
lekho("Aro cholche")
done = sotto
}
Common Mistakes
Beginners often make these mistakes:
- forgetting to update the loop variable
- using the wrong condition sign
- putting the counter change outside the loop
- expecting the loop to run when the condition is already false
Practice Task
Try writing while loops that:
- count from 1 to 5
- count backward from 10 to 1
- print a message until a flag changes
Quick Checklist
Before moving on, make sure you can:
- explain when a while loop runs
- update the loop variable inside the body
- stop the loop safely
- test the loop with different values
If yes, you understand the basic idea of the while loop.