Lesson 9 of 18

Loops

Loops

HolyC supports for and while loops — identical to C. There is one important difference: HolyC has no continue keyword.

For Loop

for (I64 i = 0; i < 5; i++) {
  Print("%d\n", i);
}

Output:

0
1
2
3
4

While Loop

I64 n = 1;
while (n <= 4) {
  Print("%d\n", n);
  n++;
}

No Continue — Use Goto

HolyC intentionally omits continue. To skip the rest of a loop body for an iteration, use goto to jump to a label at the end of the body:

for (I64 i = 0; i < 6; i++) {
  if (i == 3) goto skip;
  Print("%d\n", i);
  skip:;
}

Output:

0
1
2
4
5

The label skip: sits just before the closing brace. The semicolon after the label is required because a label must be followed by a statement (an empty statement ; works).

This design forces explicit control flow — Terry Davis believed it made code easier to reason about.

Your Task

Print the sum of all integers from 1 to 10.

Expected output: 55

Aiwnios HolyC loading...
Loading...
Click "Run" to execute your code.