Conditions
যদি (jodi) runs a block of code only when a condition is সঁচা. Add নহ'লে (nohole) for what should happen otherwise.
If
If … else
ধৰা তাপমাত্ৰা = ১২
যদি (তাপমাত্ৰা < ১৫) {
কোৱা("ঠাণ্ডা")
} নহ'লে {
কোৱা("ভাল বতৰ")
}
Output
ঠাণ্ডা
dhora tapmatra = 12
jodi (tapmatra < 15) {
kowa("thanda")
} nohole {
kowa("bhal botor")
}
Output
thanda
Several choices
Chain conditions with নহ'লে যদি (nohole jodi). The first true condition wins:
ধৰা নম্বৰ = ৮২
যদি (নম্বৰ >= ৯০) {
কোৱা("ক")
} নহ'লে যদি (নম্বৰ >= ৭৫) {
কোৱা("খ")
} নহ'লে যদি (নম্বৰ >= ৬০) {
কোৱা("গ")
} নহ'লে {
কোৱা("ঘ")
}
Output
খ
dhora nombor = 82
jodi (nombor >= 90) {
kowa("A")
} nohole jodi (nombor >= 75) {
kowa("B")
} nohole jodi (nombor >= 60) {
kowa("C")
} nohole {
kowa("D")
}
Output
B
Rules
- The condition goes in round brackets
( ), and the code in curly brackets{ }, even for one line. - The condition must be
সঁচাorমিছা.যদি (১)is an error (R007). নহ'লেcan also be writtenনহলে(without the apostrophe).
ধৰা বছৰ = ২০২৪
যদি ((বছৰ % ৪ == ০ আৰু বছৰ % ১০০ != ০) বা বছৰ % ৪০০ == ০) {
কোৱা(বছৰ, "অধিবৰ্ষ")
}
Output
২০২৪ অধিবৰ্ষ
dhora bosor = 2024
jodi ((bosor % 4 == 0 aru bosor % 100 != 0) ba bosor % 400 == 0) {
kowa(bosor, "adhibarxa")
}
Output
2024 adhibarxa