Docs Installation Playground Explore AST

Set on System Basis

Conditional Statements

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! 💡


Syntax: "Bro, Let’s Check That Condition! 🧐"

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! 🌳

BROCODE
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! 🚀

1Usage: "Bro, Is It Less Than 3? 🤔"

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! 🧑‍💻

BROCODE
bro agar (num < 3) {
  bro dikha de("Number is less than 3");
}
bro leave it {
  bro dikha de("Number is greater than 3");
}

2Another Example: "Bro, What's the Weather? 🌦️"

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!"

BROCODE
bro agar (weather == "sunny") {
  bro dikha de("Time to rock those shades! 😎");
}
bro leave it {
  bro dikha de("Grab your umbrella! ☔");
}

3Nested Conditionals: "Bro, Let's Dive Deeper! 🔄"

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!"

BROCODE
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! 😕");
}

BroCode © 2024. All rights reserved.