Defining and calling a function
karya means "task". karya naam(parameters) { ... } defines a task; writing naam(values) runs it. Parameters are like variables that get their values from the call. Define a function before the line that calls it — AltFLang reads your program from top to bottom.
lautao: give a result back
lautao ("return") ends the function and hands a value back to whoever called it. That value can be stored, printed or used in another calculation. A function that never reaches lautao gives back khali.
If you call a function with fewer values than it has parameters, the missing ones are khali.
Returning early
Because lautao exits immediately, you can use it to stop as soon as the answer is known. This keeps checks flat instead of deeply nested.
Functions that call themselves
A function may call itself — that is recursion. It needs a base case that stops the chain. AltFLang limits how deep calls can go, so a missing base case ends with an error instead of freezing your tab.
Functions are values too. rakho dugna = karya (x) { lautao x * 2; }; stores a nameless function in a variable, which is how you pass behaviour to built-ins like har later in the course.
Practice exercise
Write karya bada_kaun(a, b) that returns the larger of two numbers. Print bada_kaun(4, 9) and bada_kaun(12, 3) — expected 9 then 12.
Expected output
9 12
Show solution
karya bada_kaun(a, b) {
agar (a > b) {
lautao a;
}
lautao b;
}
bol(bada_kaun(4, 9));
bol(bada_kaun(12, 3));