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

  1. x starts at 0
  2. The condition checks whether x is less than 10
  3. If yes, the body runs
  4. lekho(x) prints the current value
  5. x++ increases the counter
  6. 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:

  1. count from 1 to 5
  2. count backward from 10 to 1
  3. 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.