LESSON 17 OF 52 · CHAPTER 02
Decisions
if, elif, else and short-circuit guards
01-decisions.srp
// Conditions are booleans; each body introduces a lexical scope.
bind score = 73;
var grade = "pending";
if score >= 90 {
grade = "A";
} elif score >= 60 and score < 90 {
grade = "B";
} else {
grade = "C";
}
print(grade);
if true or 1 / 0 == 0 {
bind message = "Selected safely.";
print(message);
}
stdout
B
Selected safely.
Write what you expect this program to print. Check prediction for a line-level hint without revealing the answer, or reveal the verified output when ready. This checks displayed text only; it does not run Scarp or save your input.
UNDERSTAND THE CODE
Explanation & practice
What this example teaches
if, elif, else and short-circuit guards
Expected behavior
Chooses a grade and prints a branch message
Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.
if, elif, else
शर्तों की क्रम से जाँच की जाती है। score के आधार पर grade चुना जाता है; दूसरी शर्त में and है।
अभ्यास: 73 अंकों के लिए कौन-सी शाखा चलेगी?
Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.
SOURCE-BACKED SELF-CHECK · स्रोत-आधारित अभ्यास
Quick checkpoint / त्वरित अभ्यास
Which grade is printed when score is 73?जब score का मान 73 है, तो कौन-सा ग्रेड प्रिंट होगा?
Reveal the source-backed answer / सही उत्तर देखें
B — 73 does not satisfy score >= 90, but it satisfies score >= 60 and score < 90, so grade becomes B.B — 73, 90 से कम और 60 से अधिक या बराबर है। इसलिए elif की शर्त सही होती है और grade का मान B बनता है।
This question checks understanding of a recorded compiler output. It does not run Scarp in the browser. यह प्रश्न सत्यापित आउटपुट पर आधारित है; ब्राउज़र में Scarp नहीं चलता।
LEARNING PROGRESS
Keep your place
Mark this lesson complete when you are ready.
Only saved in this browser. No account or tracking.
TRY IT LOCALLY
Verify, then execute
Use the pinned compiler from the course root. Keep any imported _support files next to the source.
scarp verify examples/02-control-flow/01-decisions.srp
scarp exec examples/02-control-flow/01-decisions.srpThe website does not run code. Read the CLI guide ↗
Pinned compiler: Scarp v0.0.6-alpha.3
· ceff07d9014f. No simulated output.