In BroCode, you can easily make decisions with conditional statements. Whether you’re checking if a number is smaller than 3 or deciding what action to take based on certain conditions, we’ve got you covered. Let’s dive into the syntax and usage! 💡
Conditional statements in BroCode follow a simple format. We use "bro agar" to check a condition and "bro leave it" to handle the else part. It's just like a decision tree – easy and breezy! 🌳
bro agar (condition) {
bro dikha de("Condition is true");
}
bro leave it {
bro dikha de("Condition is false");
}
Now, let’s see how to use it in action! 🚀
Let's say you want to check if a number is less than 3. If it is, we’ll show a message that says so, otherwise, we’ll let you know it's greater than 3. Here's how you do it in BroCode! 🧑💻
bro agar (num < 3) {
bro dikha de("Number is less than 3");
}
bro leave it {
bro dikha de("Number is greater than 3");
}
In this example, you could check the weather to decide what to wear. If it’s sunny, we’ll show a message saying, "Time to rock those shades!" If it's rainy, we’ll tell you, "Grab your umbrella!"
bro agar (weather == "sunny") {
bro dikha de("Time to rock those shades! 😎");
}
bro leave it {
bro dikha de("Grab your umbrella! ☔");
}
You can even nest conditionals inside each other to make more complex decisions. For example, if it's sunny but also hot, we could say, "Stay cool!" If it's sunny but not too hot, we could say, "Enjoy the sunshine!"
bro agar (weather == "sunny") {
bro agar (temp > 30) {
bro dikha de("Stay cool, bro! 😎");
}
bro leave it {
bro dikha de("Enjoy the sunshine! 🌞");
}
}
bro leave it {
bro dikha de("It’s not sunny! 😕");
}