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! 💥
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! 🏃♂️
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! ⏱️
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! 🎯
bro jbb tk (num < 3) hai {
bro dikha de(num);
bro nikal;
num++;
}
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!
bro jbb tk (pizzas < 3) hai {
bro dikha de("Eating pizza... 😋");
bro nikal;
pizzas++;
}
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! 🏃♂️💨
bro jbb tk (num < 3) hai {
bro dikha de(num);
bro agar (num == 2) hai {
bro nikal;
}
num++;
}