Docs Installation Playground Explore AST

Set on System Basis

Function Declaration

Functions in BroCode are your go-to bros for repeating actions. Once you define them, you can call them anytime to do the heavy lifting! Just pass in some parameters and let the magic happen. ✨ Let’s see how to declare and use functions with a little BroCode twist! 😎


Syntax: "Bro, I’ve Got a Function for That! 🧑‍💻"

Functions in BroCode are like your secret sauce for repeating actions. You define a function once and call it anytime you want. Just give it a name, define your parameters, and tell it what to do. Trust me, it’ll do the heavy lifting for you! 💪

BROCODE
bro function <functionName>(pram_a, param_b) {
  bro dikha de(pram_a + param_b);
}

Pro Tip: Functions are like your workout plan – write once, reuse forever. Just make sure you pass the right parameters when you call them! 🏋️

Alright, let’s put those functions to work! 🧑‍💻💥

1Usage: "Bro, Let’s Add It Up! ➕"

Here’s a simple function that adds two numbers together. Functions are super useful for repeating tasks, like adding numbers or performing operations. You give it the numbers, and it returns the result. Easy, right? 🧮

BROCODE
bro function addNumbers(pram_a, param_b) {
  bro dikha de(pram_a + param_b);
}
addNumbers(5, 3);
Context: This is like having a mini-calculator in your code. You can reuse this function anywhere to add numbers without rewriting the logic!

2Another Example: "Bro, Let’s Multiply! ✖️"

Let’s declare a function to multiply numbers. Functions are reusable, so you can call them with different inputs every time. Just imagine calling your bro to handle your multiplications! 📈

BROCODE
bro function multiplyNumbers(a, b) {
  bro dikha de(a * b);
}
multiplyNumbers(4, 2);
Context: This function takes two numbers, multiplies them, and shows the result. You can call this function anytime you need multiplication—like a calculator that never runs out of battery! 🔋

3Calling a Function: "Bro, Let’s Get It Done! ✅"

Once the function is declared, you can call it by just mentioning its name and passing in the required parameters. It’s like saying, “Yo bro, do the thing!”

BROCODE
bro function greetUser(name) {
  bro dikha de("Hello, " + name + "!");
}
greetUser("Madhav");
Context: Functions help you avoid repeating yourself. Here, we're greeting a user without having to write the same greeting logic multiple times.

BroCode © 2024. All rights reserved.