Every program starts with namaskara and ends with matte sigona. Anything outside of them is ignored, so you can write notes there. Statements end with a ;.
This line is ignored
namaskara
helu "Namaskara Jagattu!";
matte sigona
This too
Create variables with idu ("this is"). Several can be declared at once, separated by commas. A variable declared without a value is khali. Use = to change a value and +=, -=, *=, /=, %= to update it.
namaskara
idu a = 10;
idu b = "two", c;
a = a + 1;
a *= 2;
helu a, b, c;
matte sigona
Numbers and strings work like in other languages, strings can use "double" or 'single' quotes and escapes like \n, \t and \". sari and thappu are the booleans, khali means empty (null), and [ ] makes an array.
namaskara
idu sankhye = 10 + (15 * 20) / 4;
idu dashamaamsha = 3.14;
idu shabda = "Namaskara \"anna\"";
idu nijavaa = sari;
idu sullu = thappu;
idu enuilla = khali;
idu patti = [1, "eradu", sari];
helu sankhye, dashamaamsha, shabda;
helu nijavaa, sullu, enuilla, patti;
matte sigona
helu ("say") prints values. Separate several values with commas and they are printed on one line with spaces in between.
namaskara
helu "Hello World";
idu a = 10;
{
idu b = 20;
helu a + b;
}
helu 5, 'ok', khali, sari, thappu;
matte sigonaArithmetic: + - * / %. Comparison: == != < <= > >=. Logical: mattu (and, &&), athava (or, ||) and alla (not, !). Adding a string to a number joins them.
namaskara
idu a = 7;
helu a + 3, a - 3, a * 3, a / 2, a % 3, -a;
helu a > 5, a == 7, a != 7;
helu (a > 5) mattu (a < 10), sari athava thappu, alla sari;
helu "Score: " + a;
matte sigona
enadru (if) runs a block when its condition is sari. Add any number of illa andre (else if) blocks and finish with an optional enu illa andre (else). thappu, khali, 0 and "" count as false, everything else as true.
namaskara
idu a = 10;
enadru (a < 20) {
helu "a is less than 20";
} illa andre (a < 25) {
helu "a is less than 25";
} enu illa andre {
helu "a is greater than or equal to 25";
}
matte sigonaellivargu ("until when", while) repeats its block as long as the condition is sari. Use saaku nilsu ("enough, stop") to leave the loop and munde nodu ("look ahead") to skip to the next round.
namaskara
idu a = 0;
ellivargu (a < 10) {
a += 1;
enadru (a == 5) {
helu "loop olaginda helu", a;
munde nodu;
}
enadru (a == 7) {
saaku nilsu;
}
helu a;
}
helu "done";
matte sigonaprathi ("for every") is a counting loop: prathi (start; condition; step). The loop variable only exists inside the loop. Every part is optional, prathi (;;) loops until saaku nilsu.
namaskara
prathi (idu i = 1; i <= 5; i += 1) {
helu i, "x 9 =", i * 9;
}
matte sigonaCreate functions with kelasa ("work") and give back a value with kodu ("give"). A function without kodu gives khali. Functions can call themselves (recursion), be stored in variables and passed to other functions.
namaskara
kelasa jodisu(a, b) {
kodu a + b;
}
kelasa factorial(n) {
enadru (n <= 1) {
kodu 1;
}
kodu n * factorial(n - 1);
}
helu jodisu(2, 3);
helu factorial(5);
matte sigonaArrays hold a list of values: [1, 2, 3]. Read and change elements with list[index], indexes start at 0. Strings can be indexed too. Use uddha, serisu and tegi to get the length, add and remove elements.
namaskara
idu hannu = ["mavu", "bale"];
serisu(hannu, "halasu");
hannu[0] = "seebe";
prathi (idu i = 0; i < uddha(hannu); i += 1) {
helu i, hannu[i];
}
helu hannu, "Kannada"[0];
matte sigonaKannada Script comes with a few helpful functions. Each one also has a Kannada script name, e.g. ಉದ್ದ for uddha. See the table in Keywords.
namaskara
helu uddha("namaskara"), uddha([1, 2]);
helu sankhye("41") + 1, pada(41) + 1;
helu poorna(7 / 2);
idu stack = [];
serisu(stack, 1);
serisu(stack, 2);
helu tegi(stack), stack;
matte sigonakelu ("ask") reads a line of input and gives it as a string, use sankhye to turn it into a number. In the playground, answers come from the Input tab (one per line), otherwise the browser asks you.
namaskara
idu hesaru = kelu("Ninna hesaru? ");
idu a = sankhye(kelu("Ondu sankhye: "));
helu "Namaskara " + hesaru + "!", a, "x 2 =", a * 2;
matte sigonaEvery keyword can also be written in Kannada script, and variable names can use Kannada letters and digits (೦–೯). Mix both as you like. The ಕನ್ನಡ ಲಿಪಿ button in the playground converts a program between the two.
ನಮಸ್ಕಾರ
ಇದು ಹೆಸರು = "ಕನ್ನಡ";
ಏನಾದ್ರು (ಉದ್ದ(ಹೆಸರು) > ೨) {
ಹೇಳು "ನಮಸ್ಕಾರ " + ಹೆಸರು;
} ಏನೂ ಇಲ್ಲ ಅಂದ್ರೆ {
ಹೇಳು ಖಾಲಿ;
}
ಮತ್ತೆ ಸಿಗೋಣWhen something goes wrong, Kannada Script tells you what happened, in Kannada with an English hint. Syntax errors show the line and column, in the playground that line is highlighted and you can jump to it. Infinite loops and runaway recursion are stopped automatically.
namaskara
idu a = 10
helu a;
matte sigona