MarathiCodev1.0
by Sprout Tech
Official Language Samples

MarathiCode Practical Examples

These code examples illustrate fundamental programming concepts written in MarathiCode. You can launch any example directly into the interactive playground.

1. Hello World (नमसकार)

examples/hello.mr

Source Code (.mr):
छापा("नमसकार")
Expected Output:
>नमसकार
Explanation:
  • छापा is the built-in output function.
  • "नमसकार" is a double-quoted string literal.
  • Output displays नमसकार on standard output.

2. Variable Addition (बेरीज)

examples/add.mr

Source Code (.mr):
चल अ = ४
चल म = 5.8
छापा( अ + म )
Expected Output:
>9.8
Explanation:
  • चल declares variable अ initialized to Devanagari digit ४ (4).
  • चल म stores standard decimal float 5.8.
  • छापा(अ + म) evaluates 4 + 5.8 to 9.8.

3. Conditional Logic (जर - नाहीतर)

examples/if.mr

Source Code (.mr):
चल अ = १०
जर अ > ११ तर {
    छापा("खरे")
} नाहीतर {
    छापा("खोटे")
}
Expected Output:
>खोटे
Explanation:
  • चल अ is set to 10.
  • The expression अ > 11 evaluates to खोटे (False).
  • The नाहीतर (else) block executes, printing खोटे.

4. Functions & Return (क्षेत्रफळ व परिमिती)

examples/rectangle_function.mr

Source Code (.mr):
कार्य क्षेत्र(ल, म) {
    परत ल * म
}

कार्य परिमिती(ल, म) {
    परत 2 * (ल + म)
}

चल a = क्षेत्र(10, 20)
चल p = परिमिती(10, 20)
छापा(a)
छापा(p)
Expected Output:
>200
>60
Explanation:
  • Define function क्षेत्र (Area) taking length (ल) and width (म).
  • Define function परिमिती (Perimeter) taking length and width.
  • Evaluate क्षेत्र(10, 20) => 200.
  • Evaluate परिमिती(10, 20) => 2 * (10 + 20) = 60.

5. Counter Loop (पर्यंत लूप)

examples/while_counter.mr

Source Code (.mr):
चल counter = १
पर्यंत counter <= ५ {
    छापा(counter)
    चल counter = counter + १
}
Expected Output:
>1
>2
>3
>4
>5
Explanation:
  • Initializes variable counter to 1.
  • Checks condition counter <= 5 on each iteration.
  • Increments counter by 1 until condition becomes false.