LESSON 19 OF 52 · CHAPTER 02

Repeat

repeat N as index with a fixed count

ORIGINAL SOURCE

03-repeat.srp

// The count is saved once; changing count does not shorten this loop.
var count = 5;
var total = 0;
repeat count as index {
    count = 0;
    if index == 2 { continue; }
    total += index;
}
print(total);
print(count);
EXPECTED OUTPUT

stdout

Verified
8
0

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

repeat N as index with a fixed count

Expected behavior

Prints 8 then 0

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

repeat count as index शुरुआत में गिनती तय कर लेता है। बाद में count को शून्य करने से चक्करों की पहले से तय संख्या नहीं बदलती।

अभ्यास: index == 2 पर continue होने पर total क्या बनता है?

Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.

SOURCE-BACKED SELF-CHECK · स्रोत-आधारित अभ्यास

Quick checkpoint / त्वरित अभ्यास

What total is printed when repeat skips index 2?repeat में index 2 को छोड़ने पर कौन-सा total प्रिंट होता है?

Reveal the source-backed answer / सही उत्तर देखें

8 — repeat saves the initial count of five iterations. The indices 0, 1, 3 and 4 sum to 8; assigning count = 0 does not shorten the loop.8 — repeat शुरुआत की पाँच पुनरावृत्तियाँ तय कर लेता है। index 0, 1, 3 और 4 का योग 8 है; count = 0 करने से लूप छोटा नहीं होता।

This question checks understanding of a recorded compiler output. It does not run Scarp in the browser. यह प्रश्न सत्यापित आउटपुट पर आधारित है; ब्राउज़र में Scarp नहीं चलता।

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/03-repeat.srp scarp exec examples/02-control-flow/03-repeat.srp

The website does not run code. Read the CLI guide ↗

Pinned compiler: Scarp v0.0.6-alpha.3 · ceff07d9014f. No simulated output.