Docs Installation Playground Explore AST

Set on System Basis

While Loop

In BroCode, a while loop keeps running as long as your condition is true. If your number is less than 3, we’ll keep showing it! But if you’ve had enough, just say “bro nikal” to break free. 😎 Let’s see the syntax and a couple of fun examples! 💥


Syntax: "Bro, Keep Going Until It's Done! 🔁"

While loops let you repeat actions based on a condition. In BroCode, we use "bro jbb tk" to keep checking the condition and "bro nikal" to stop when we’ve had enough. It’s like a treadmill – keep going or hit the stop button! 🏃‍♂️

BROCODE
bro jbb tk (condition) hai {
  bro dikha de("Action is happening!");
  bro nikal;
  num++;
}

Pro Tip: Use 'bro nikal' to break out of the loop early, just like calling it quits when you're done – no need to keep going if you've reached your goal! 🛑

Time to see it in action! ⏱️

1Usage: "Bro, Let's Count! 🔢"

Let’s say you want to keep showing numbers as long as it’s less than 3. Here’s how you can do it with a while loop. Each time the number increases, we keep showing it, and once we hit the "break" condition, we stop! 🎯

BROCODE
bro jbb tk (num < 3) hai {
  bro dikha de(num);
  bro nikal;
  num++;
}

2Another Example: "Bro, I’m Hungry! 🍕"

Imagine checking how many pizzas you can eat while you’re still hungry. Keep eating until you're full (or your stomach says "bro nikal"). Here's how a while loop can help with that!

BROCODE
bro jbb tk (pizzas < 3) hai {
  bro dikha de("Eating pizza... 😋");
  bro nikal;
  pizzas++;
}

3Breaking Out Early: "Bro, I've Had Enough! 😅"

If you want to exit the loop early, use the "bro nikal" command! In this example, we’ll stop the loop as soon as we see a number greater than 2. Quick exit, no questions asked! 🏃‍♂️💨

BROCODE
bro jbb tk (num < 3) hai {
  bro dikha de(num);
  bro agar (num == 2) hai {
    bro nikal;
  }
  num++;
}

BroCode © 2024. All rights reserved.