LESSON 20 OF 52 · CHAPTER 02
Nested Repeat
Nested repeat loops, inner continue, and counters
04-nested-repeat.srp
// Nested repeats produce a small grid; continue skips only the inner loop.
var accepted = 0;
var skipped = 0;
var total = 0;
repeat 4 as row {
repeat 3 as column {
if row == column {
skipped += 1;
continue;
}
accepted += 1;
total += row + column;
}
}
print(accepted, skipped, total);
stdout
9 3 24
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
Nested repeat loops, inner continue, and counters
Expected behavior
Prints 9 3 24
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.
नेस्टेड repeat और continue
बाहरी repeat 4 as row की हर पुनरावृत्ति में अंदर का repeat 3 as column चलता है। इस तरह 12 (row, column) जोड़ियाँ बनती हैं। row == column होने पर continue केवल अंदर वाले लूप के मौजूदा चक्कर को छोड़ता है। ऐसी तीन जोड़ियाँ हैं: (0, 0), (1, 1), (2, 2)। बाकी 9 जोड़ियों के row + column का योग 24 है।
अभ्यास: अगर repeat 3 as column की संख्या 4 हो जाए, तो कितनी जोड़ियाँ और कितने continue होंगे? अनुमान लगाकर कंपाइलर से जाँचें।
Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.
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/04-nested-repeat.srp
scarp exec examples/02-control-flow/04-nested-repeat.srpThe website does not run code. Read the CLI guide ↗
CHAPTER 02 · LAST LESSON
Ready for your next step? · आगे क्या सीखें?
This is the final example in this chapter. Try its verified coding lab before moving on. Your lesson progress changes only when you mark a lesson complete.
Pinned compiler: Scarp v0.0.6-alpha.3
· ceff07d9014f. No simulated output.