म
MarathiCodeby Sprout Tech
Documentation topicsVariables
MarathiCode v0.2.0

Variables

चल <नाव> = <मूल्य>

चल declares a variable in the current scope. Assigning without चल changes an existing variable.

variables.mr
चल संख्या = 10
संख्या = संख्या + 5
छापा(संख्या)
Output (आउटपुट)
15

Dynamic typing

A variable can hold any kind of value, and can later hold a different kind:

dynamic.mr
चल x = 42
छापा(x)
x = "आता मजकूर"
छापा(x)
x = [1, 2]
छापा(x)
Output (आउटपुट)
42
आता मजकूर
[1, 2]

चल versus plain assignment

StatementWhat it does
चल x = 5Creates x in the current scope. Inside a block this hides any outer x.
x = 5Changes the nearest existing x (current scope, then outer scopes, then global).
x = 5 (no x anywhere)Creates x in the current scope, as if चल had been used.
declare_vs_assign.mr
चल x = 1
जर खरे तर {
    x = 2
}
छापा(x)
जर खरे तर {
    चल x = 3
}
छापा(x)
Output (आउटपुट)
2
2

See Scope for the full rules. Reading a variable that does not exist is a runtime error.