asomiya 0.2.0

Control flow

Loops

যেতিয়ালৈকে (jetialoike) means “for as long as”. It runs its block again and again while the condition stays সঁচা.

Repeat while true

ধৰা ক = ১
ধৰা যোগফল = ০
যেতিয়ালৈকে (ক <= ১০) {
    যোগফল = যোগফল + ক
    ক = ক + ১
}
কোৱা("১ ৰ পৰা ১০ লৈ যোগফল:", যোগফল)
Output
১ ৰ পৰা ১০ লৈ যোগফল: ৫৫
dhora k = 1
dhora jugfol = 0
jetialoike (k <= 10) {
    jugfol = jugfol + k
    k = k + 1
}
kowa("1-10 jugfol:", jugfol)
Output
1-10 jugfol: 55

Watch out

Remember to change the variable in the condition, or the loop never ends. Asomiya stops runaway programs after about 10 million steps (R008), and the playground has a Stop button.

Stop early: ৰখা

ৰখা (rokha, “stop”) leaves the loop immediately:

ধৰা ন = ১
যেতিয়ালৈকে (সঁচা) {
    যদি (ন * ন > ৫০) {
        ৰখা
    }
    ন = ন + ১
}
কোৱা("প্ৰথম সংখ্যা যাৰ বৰ্গ ৫০ তকৈ বেছি:", ন)
Output
প্ৰথম সংখ্যা যাৰ বৰ্গ ৫০ তকৈ বেছি: ৮
dhora n = 1
jetialoike (xosa) {
    jodi (n * n > 50) {
        rokha
    }
    n = n + 1
}
kowa("first number whose square > 50:", n)
Output
first number whose square > 50: 8

Skip ahead: আগবাঢ়া

আগবাঢ়া (aagbara, “go forward”) skips the rest of this round and starts the next one:

ধৰা ক = ০
যেতিয়ালৈকে (ক < ১০) {
    ক = ক + ১
    যদি (ক % ২ == ০) {
        আগবাঢ়া
    }
    কোৱা(ক)
}
Output
১
৩
৫
৭
৯
dhora k = 0
jetialoike (k < 10) {
    k = k + 1
    jodi (k % 2 == 0) {
        aagbara
    }
    kowa(k)
}
Output
1
3
5
7
9

Loops inside loops

ধৰা শাৰী = ১
যেতিয়ালৈকে (শাৰী <= ৪) {
    ধৰা ৰেখা = ""
    ধৰা গণনা = ০
    যেতিয়ালৈকে (গণনা < শাৰী) {
        ৰেখা = ৰেখা + "★"
        গণনা = গণনা + ১
    }
    কোৱা(ৰেখা)
    শাৰী = শাৰী + ১
}
Output
★
★★
★★★
★★★★
dhora xari = 1
jetialoike (xari <= 4) {
    dhora rekha = ""
    dhora gonona = 0
    jetialoike (gonona < xari) {
        rekha = rekha + "★"
        gonona = gonona + 1
    }
    kowa(rekha)
    xari = xari + 1
}
Output
★
★★
★★★
★★★★

ৰখা and আগবাঢ়া only affect the innermost loop. Using them outside a loop is an error.