म
MarathiCodeby Sprout Tech
Documentation topicsOperators
MarathiCode v0.2.0

Operators

अंकगणितीय, तुलना व तार्किक ऑपरेटर

Arithmetic

OperatorMeaningExampleResult
+Addition; joins strings; joins two lists10 + 515
-Subtraction; unary minus10 - 15-5
*Multiplication4 * 2.510
/Division (always true division)7 / 23.5
%Remainder (sign follows the left side)-7 % 3-1

-, *, / and % work on numbers only. + adds two numbers, joins two lists, or, when either side is a string, joins text. Any other combination is a runtime error.

Comparison

OperatorMeaningExampleResult
==Equal2 + 2 == 4खरे
!=Not equal"अ" != "ब"खरे
>Greater than10 > 5खरे
<Less than10 < 5खोटे
>=Greater than or equal5 >= 5खरे
<=Less than or equal4 <= 3खोटे
  • == and != work on any values. Values of different kinds are never equal, and lists are compared element by element.
  • >, <, >=, <= need two numbers or two strings.

Logical

OperatorMeaning
आणिAND: true when both sides are true
किंवाOR: true when at least one side is true
नाहीNOT: reverses a value (unary)

आणि and किंवा are short-circuit operators: the right side is evaluated only when the left side does not already decide the result. They return the deciding value itself.

short_circuit.mr
कार्य तपासा() {
    छापा("उजवी बाजू तपासली")
    परत खरे
}

छापा(खोटे आणि तपासा())
छापा(खरे किंवा तपासा())
छापा(खरे आणि तपासा())
छापा(0 किंवा "पर्याय")
Output (आउटपुट)
खोटे
खरे
उजवी बाजू तपासली
खरे
पर्याय

Short-circuiting also lets a condition guard the expression after it:

guard.mr
चल यादी = []
जर लांबी(यादी) > 0 आणि यादी[0] == 5 तर {
    छापा("पहिली संख्या 5")
} नाहीतर {
    छापा("तपासले नाही")
}
Output (आउटपुट)
तपासले नाही

The order in which operators apply is described in Operator Precedence.