Custom Functions

Learn how to define your own functions using `kaj` and `ferotDao` in BornomalaScript.

Custom Functions

Custom functions are functions that you write yourself.

They let you package reusable logic into one named block so you can call it whenever you need it.

Basic Example

Define and call:

kaj jogKoro(num1, num2) {
  ferotDao num1 + num2
}

dhoro jogFol = jogKoro(5, 10)
lekho(jogFol)

kaj AmarKaj(x) {
    lekho(x)
}
AmarKaj("ami na korle ke korbe")

This example shows two custom functions:

  • jogKoro adds two numbers and returns the result
  • AmarKaj prints the value it receives

How It Works

The first function uses ferotDao to send a value back to the caller.

The second function does not return anything. It simply performs an action.

That means custom functions can either:

  • return a result
  • perform a task
  • do both, depending on the program design

Step-by-Step Breakdown

  1. Define the function with kaj
  2. Choose the parameter names
  3. Put the logic inside the function body
  4. Use ferotDao if you want to send a result back
  5. Call the function by name when you need it

Why Custom Functions Matter

Custom functions help you:

  • reuse logic
  • keep code organized
  • reduce repetition
  • make larger programs easier to understand

Try These Variations

Practice with more small functions:

kaj BoroKoro(x) {
  ferotDao x * 2
}

lekho(BoroKoro(5))
kaj Shagotom(name) {
  lekho("Shagotom, " + name)
}

Shagotom("Amina")
kaj Jomma(a, b) {
  ferotDao a + b
}

dhoro result = Jomma(10, 20)
lekho(result)

Common Mistakes

Beginners often make these mistakes:

  • forgetting to call the function after defining it
  • passing the wrong number of arguments
  • forgetting ferotDao when a result is needed
  • using unclear parameter names

Practice Task

Try writing custom functions that:

  1. greet a person by name
  2. add two numbers
  3. print a message using an argument

Quick Checklist

Before moving on, make sure you can:

  • define a function with kaj
  • pass values into it
  • return a result with ferotDao
  • call the function when needed

If yes, you understand the basics of custom functions.