Documentation topicsBreak & Continue
Lexical Structure
Control Flow
Functions & Scope
Lists & Built-ins
Reference
MarathiCode v0.2.0
Break & Continue
थांब व पुढे
| Keyword | Effect |
|---|---|
| थांब | Leaves the innermost loop immediately. |
| पुढे | Skips the rest of the current iteration and continues with the next one. |
break_continue.mr
साठी (i = 1; i <= 10; i = i + 1) {
जर i == 3 तर {
पुढे
}
जर i == 6 तर {
थांब
}
छापा(i)
}Output (आउटपुट)
1 2 4 5
In a साठी loop, पुढे still runs the update part (i = i + 1) before the next check. In a पर्यंत loop it goes straight back to the condition, so update the counter beforeपुढे:
while_continue.mr
चल n = 0
पर्यंत n < 6 {
n = n + 1
जर n % 2 == 0 तर {
पुढे
}
छापा(n)
}Output (आउटपुट)
1 3 5
In nested loops, थांब only leaves the inner loop:
nested_break.mr
साठी (i = 1; i <= 2; i = i + 1) {
साठी (j = 1; j <= 3; j = j + 1) {
जर j == 2 तर {
थांब
}
छापा(i + "-" + j)
}
}Output (आउटपुट)
1-1 2-1
Using
थांब or पुढे outside a loop is a runtime error. They also cannot jump out of a function into a loop that called it.