C for Loop: Syntax, Execution Steps, and Flowchart
What is C for Loop: Syntax, Execution Steps, and Flowchart? Ask a working C programmer which loop they use most, and the answer is almost always the same: for. It's the counting specialist — the loop you reach for w...
What is the internal execution cycle of a C `for` loop: initialization, condition, body, and increment expression?
Explanation & In-Depth Details
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">initialization</span><span class="js-op">;</span>
<span class="js-id">condition</span><span class="js-op">;</span>
<span class="js-id">update</span><span class="js-op">)</span> <span class="js-op">{</span>
<span class="js-cm">// loop body</span>
<span class="js-op">}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Three expressions inside the parentheses, separated by <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">semicolons</span> (not commas — a classic typo):</p><div class="my-4 flex flex-col gap-2 rounded-lg bg-sidebar p-2" data-streamdown="table-wrapper" style="border-width: 0.8px; border-style: solid; border-color: rgb(47, 47, 55); border-image: none 100% / 1 / 0 stretch; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 0.5rem; margin-block: 1rem 0.75rem; overflow: hidden; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); gap: 0px; --tw-space-y-reverse: 0; display: flex; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px;"><div class="border-collapse" style="border: 1px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); border-collapse: collapse; border-radius: 5.5px; background-color: rgb(18, 18, 22); max-height: 300px;"><table class="w-full divide-y divide-border" data-streamdown="table" style="border-width: 0px; border-color: inherit; margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); text-indent: 0px; min-width: 100%; width: 956.8px;"><thead class="bg-muted/80" data-streamdown="table-header" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0; background-color: oklab(0.252138 0.000131465 -0.00581433 / 0.8);"><tr class="" data-streamdown="table-row" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Part</th><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Purpose</th><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Runs How Often</th></tr></thead><tbody class="divide-y divide-border" data-streamdown="table-body" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">initialization</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Sets up the loop counter</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Exactly once</span>, at the start</td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">condition</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Decides whether to continue</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Before <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">every</span> iteration</td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">update</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Moves the counter forward</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">After</span> every iteration</td></tr><tr class="" data-streamdown="table-row" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">body</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">The work being repeated</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Once per iteration</td></tr></tbody></table></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">A concrete example to hold onto:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d "</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">);}//</span> <span class="js-id">Output</span><span class="js-op">:</span> <span class="js-num">1</span> <span class="js-num">2</span> <span class="js-num">3</span> <span class="js-num">4</span> <span class="js-num">5</span></code></pre></div></div></div><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">The Exact Execution Order (Step by Step)</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Most beginners assume the loop just reads left to right. It doesn't. Here's the <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">actual</em> sequence C follows:</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-num">1</span><span class="js-op">.</span> <span class="js-id">initialization</span> → <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span> <span class="js-op">(</span><span class="js-id">once</span><span class="js-op">,</span> <span class="js-id">ever</span><span class="js-op">)</span><span class="js-num">2</span><span class="js-op">.</span> <span class="js-id">condition</span> <span class="js-id">check</span> → <span class="js-id">is</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">?</span> ├─ <span class="js-num">false</span> → <span class="js-id">EXIT</span> <span class="js-id">the</span> <span class="js-id">loop</span> └─ <span class="js-num">true</span> → <span class="js-id">continue3</span><span class="js-op">.</span> <span class="js-id">body</span> → <span class="js-id">print</span> <span class="js-id">i4</span><span class="js-op">.</span> <span class="js-id">update</span> → <span class="js-id">i</span><span class="js-op">++</span><span class="js-num">5</span><span class="js-op">.</span> <span class="js-id">back</span> <span class="js-id">to</span> <span class="js-id">step</span> <span class="js-num">2</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Watch it play out with <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for (int i = 1; i <= 3; i++)</code>:</p><div class="my-4 flex flex-col gap-2 rounded-lg bg-sidebar p-2" data-streamdown="table-wrapper" style="border-width: 0.8px; border-style: solid; border-color: rgb(47, 47, 55); border-image: none 100% / 1 / 0 stretch; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 0.5rem; margin-block: 1rem 0.75rem; overflow: hidden; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); gap: 0px; --tw-space-y-reverse: 0; display: flex; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px;"><div class="border-collapse" style="border: 1px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); border-collapse: collapse; border-radius: 5.5px; background-color: rgb(18, 18, 22); max-height: 300px;"><table class="w-full divide-y divide-border" data-streamdown="table" style="border-width: 0px; border-color: inherit; margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); text-indent: 0px; min-width: 100%; width: 951.2px;"><thead class="bg-muted/80" data-streamdown="table-header" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0; background-color: oklab(0.252138 0.000131465 -0.00581433 / 0.8);"><tr class="" data-streamdown="table-row" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Step</th><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Action</th><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">i</th><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Output</th></tr></thead><tbody class="divide-y divide-border" data-streamdown="table-body" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Init</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">i = 1</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">1</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Check</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">1 <= 3? ✓</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">1</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Body</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">print</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">1</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">1</code></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Update</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">i++</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">2</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Check</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">2 <= 3? ✓</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">2</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Body</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">print</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">2</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">2</code></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Update</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">i++</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">3</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Check</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">3 <= 3? ✓</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">3</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Body</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">print</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">3</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">3</code></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Update</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">i++</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">4</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"></td></tr><tr class="" data-streamdown="table-row" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Check</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">4 <= 3? ✗</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">—</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">EXIT</span></td></tr></tbody></table></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Two details worth memorizing from that table:</p><ul class="list-inside list-disc whitespace-normal [li_&]:pl-6" data-streamdown="unordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">The condition is checked BEFORE the body</span> — so if it's false immediately, the body never runs (zero iterations is perfectly legal)</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">The update runs AFTER the body</span>, not before — that's why <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">i = 1</code> gets printed on the first pass</li></ul><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">(Suggested image: this trace table as an infographic — "anatomy of 3 iterations" — highly shareable for students)</em></p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">First Programs: Counting Both Ways</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Counting up:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">10</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d "</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">);}//</span> <span class="js-num">1</span> <span class="js-num">2</span> <span class="js-num">3</span> <span class="js-num">4</span> <span class="js-num">5</span> <span class="js-num">6</span> <span class="js-num">7</span> <span class="js-num">8</span> <span class="js-num">9</span> <span class="js-num">10</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Counting down</span> (flip the condition, flip the update):</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">10</span><span class="js-op">;</span>
<span class="js-id">i</span> <span class="js-op">>=</span> <span class="js-num">1</span><span class="js-op">;</span>
<span class="js-id">i</span><span class="js-op">--)</span> <span class="js-op">{</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d "</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">);</span>
<span class="js-op">}</span>
<span class="js-id">puts</span><span class="js-op">(</span><span class="js-str">"Blast off!"</span><span class="js-op">);//</span> <span class="js-num">10</span> <span class="js-num">9</span> <span class="js-num">8</span> <span class="js-num">7</span> <span class="js-num">6</span> <span class="js-num">5</span> <span class="js-num">4</span> <span class="js-num">3</span> <span class="js-num">2</span> <span class="js-num">1</span> <span class="js-id">Blast</span> <span class="js-id">off</span><span class="js-op">!</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Custom steps</span> — the update doesn't have to be <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">++</code>:</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">20</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op">+=</span> <span class="js-num">2</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d "</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">);}//</span> <span class="js-num">0</span> <span class="js-num">2</span> <span class="js-num">4</span> <span class="js-num">6</span> <span class="js-num">8</span> <span class="js-num">10</span> <span class="js-num">12</span> <span class="js-num">14</span> <span class="js-num">16</span> <span class="js-num">18</span> <span class="js-num">20</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">The classic — sum of first N natural numbers:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;">#<span class="js-id">include</span> <span class="js-op"><</span><span class="js-id">stdio</span><span class="js-op">.</span><span class="js-id">h</span><span class="js-op">></span>
<span class="js-id">int</span> <span class="js-id">main</span><span class="js-op">()</span> <span class="js-op">{</span> <span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">,</span> <span class="js-id">sum</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">;</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Enter n: "</span><span class="js-op">);</span> <span class="js-id">scanf</span><span class="js-op">(</span><span class="js-str">"%d"</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">n</span><span class="js-op">);</span>
<span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-id">n</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">sum</span> <span class="js-op">+=</span> <span class="js-id">i</span><span class="js-op">;</span> <span class="js-op">}</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Sum of 1 to %d = %d\n"</span><span class="js-op">,</span> <span class="js-id">n</span><span class="js-op">,</span> <span class="js-id">sum</span><span class="js-op">);</span> <span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Sample Run:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">Enter</span> <span class="js-id">n</span><span class="js-op">:</span> 100Sum <span class="js-kw">of</span> <span class="js-num">1</span> <span class="js-id">to</span> <span class="js-num">100</span> <span class="js-op">=</span> <span class="js-num">5050</span></code></pre></div></div></div><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">The Header Is Flexible: Variations You Should Recognize</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">The three header slots are more permissive than they look. All of these are legal:</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Declare the counter outside</span> (needed if you use it after the loop):</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">int</span> <span class="js-id">i</span><span class="js-op">;</span><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d "</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">);}</span><span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"\nStopped at i = %d\n"</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">);</span> <span class="js-cm">// i survives here — prints 6</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Multiple variables with commas:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">,</span> <span class="js-id">j</span> <span class="js-op">=</span> <span class="js-num">10</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><</span> <span class="js-id">j</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++,</span> <span class="js-id">j</span><span class="js-op">--)</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"i=%d j=%d\n"</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">,</span> <span class="js-id">j</span><span class="js-op">);}//</span> <span class="js-id">i</span><span class="js-op">=</span><span class="js-num">1</span> <span class="js-id">j</span><span class="js-op">=</span><span class="js-num">10</span><span class="js-cm">// i=2 j=9// ... until they cross</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Omit any part</span> (the semicolons must stay!):</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span><span class="js-kw">for</span> <span class="js-op">(</span> <span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-op">}</span> <span class="js-cm">// init outside</span>
<span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">k</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">k</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-op">)</span> <span class="js-op">{</span> <span class="js-cm">// update inside body printf("%d ", k); k++;}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Omit everything</span> — the intentional infinite loop:</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(;;)</span> <span class="js-op">{</span>
<span class="js-cm">// runs forever — needs a break inside printf("Press 0 to quit: ");</span>
<span class="js-id">int</span> <span class="js-id">choice</span><span class="js-op">;</span>
<span class="js-id">scanf</span><span class="js-op">(</span><span class="js-str">"%d"</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">choice</span><span class="js-op">);</span>
<span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">choice</span> <span class="js-op">==</span> <span class="js-num">0</span><span class="js-op">)</span> <span class="js-kw">break</span><span class="js-op">;</span>
<span class="js-op">}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Watch out:</span> <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for (;;)</code> is a deliberate infinite loop, same as <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">while (1)</code>. Omitting the condition doesn't mean "no condition" — C treats a missing condition as <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">always true</em>.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Nested for Loops: Grids and Patterns</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Put a <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code> inside a <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code>, and the inner loop runs <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">completely</span> for every single pass of the outer one. This is how you work in two dimensions:</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">row</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">row</span> <span class="js-op"><=</span> <span class="js-num">3</span><span class="js-op">;</span> <span class="js-id">row</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">col</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">col</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-id">col</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"* "</span><span class="js-op">);</span> <span class="js-op">}</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"\n"</span><span class="js-op">);</span> <span class="js-cm">// new line after each row}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Output:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">**</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">**</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">*</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">3 rows × 5 columns = 15 stars. The outer loop controls <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">rows</em>, the inner loop controls <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">columns</em>, and the newline sits between them. This outer/inner rhythm is the skeleton of every pattern program.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">(Suggested image: a visual showing the grid with row numbers on the left, column numbers on top, and arrows marking which loop controls which dimension)</em></p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">The Classic Pattern Programs</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Every C course assigns these, and for good reason — they're the fastest way to build loop intuition. The trick is always the same: <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">find the formula connecting row number to inner-loop count.</span></p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Right triangle:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">j</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">j</span> <span class="js-op"><=</span> <span class="js-id">i</span><span class="js-op">;</span> <span class="js-id">j</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-cm">// inner count = row number! printf("* "); } printf("\n");}</span></code></pre></div></div></div><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-op">**</span> <span class="js-op">**</span> <span class="js-op">*</span> <span class="js-op">**</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">**</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">*</span> <span class="js-op">*</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Number triangle:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">4</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">j</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">j</span> <span class="js-op"><=</span> <span class="js-id">i</span><span class="js-op">;</span> <span class="js-id">j</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d "</span><span class="js-op">,</span> <span class="js-id">j</span><span class="js-op">);</span> <span class="js-op">}</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"\n"</span><span class="js-op">);}</span></code></pre></div></div></div><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-num">11</span> <span class="js-num">21</span> <span class="js-num">2</span> <span class="js-num">31</span> <span class="js-num">2</span> <span class="js-num">3</span> <span class="js-num">4</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Pyramid (the famous one)</span> — two inner loops: spaces, then stars:</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">int</span> <span class="js-id">n</span> <span class="js-op">=</span> <span class="js-num">5</span><span class="js-op">;</span>
<span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-id">n</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">s</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">s</span> <span class="js-op"><=</span> <span class="js-id">n</span> <span class="js-op">-</span> <span class="js-id">i</span><span class="js-op">;</span> <span class="js-id">s</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-cm">// spaces shrink printf(" "); } for (int j = 1; j <= 2 * i - 1; j++) { // stars grow: 1, 3, 5, 7... printf("*"); } printf("\n");}</span></code></pre></div></div></div><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"> <span class="js-op">*</span> <span class="js-op">***</span> <span class="js-op">*****</span> <span class="js-op">****************</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Don't memorize these — <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">derive</span> them. Ask: "in row <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">i</code>, how many spaces? how many stars?" The formulas (<code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">n - i</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">2*i - 1</code>) fall out of that question every time.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">for vs while: When the Counter Wins</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Since any loop can imitate any other, here's the honest comparison:</p><div class="my-4 flex flex-col gap-2 rounded-lg bg-sidebar p-2" data-streamdown="table-wrapper" style="border-width: 0.8px; border-style: solid; border-color: rgb(47, 47, 55); border-image: none 100% / 1 / 0 stretch; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 0.5rem; margin-block: 1rem 0.75rem; overflow: hidden; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); gap: 0px; --tw-space-y-reverse: 0; display: flex; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px;"><div class="border-collapse" style="border: 1px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); border-collapse: collapse; border-radius: 5.5px; background-color: rgb(18, 18, 22); max-height: 300px;"><table class="w-full divide-y divide-border" data-streamdown="table" style="border-width: 0px; border-color: inherit; margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); text-indent: 0px; min-width: 100%; width: 956.8px;"><thead class="bg-muted/80" data-streamdown="table-header" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0; background-color: oklab(0.252138 0.000131465 -0.00581433 / 0.8);"><tr class="" data-streamdown="table-row" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Situation</th><th class="whitespace-nowrap px-4 py-2 text-left font-semibold text-sm" data-streamdown="table-header-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px; --tw-font-weight: 600; text-wrap-mode: nowrap;">Better Choice</th></tr></thead><tbody class="divide-y divide-border" data-streamdown="table-body" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Counted repetitions (1 to N)</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Loop until a condition changes</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">while</code></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Must run at least once</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">do-while</code></td></tr><tr class="" data-streamdown="table-row" style="border-bottom-width: 0.8px; border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-divide-y-reverse: 0;"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Array/table processing</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code></td></tr><tr class="" data-streamdown="table-row" style="border-color: rgb(47, 47, 55); border-image: initial; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);"><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;">Input validation (unknown attempts)</td><td class="px-4 py-2 text-sm" data-streamdown="table-cell" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-inline: 15px; padding-block: 7.5px; font-size: 13px; line-height: 18.75px;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">while</code> / <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">do-while</code></td></tr></tbody></table></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">The <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code> loop's killer feature isn't power — it's <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">locality</span>. Initialization, condition, and update sit on one line, so the entire "story" of the loop is visible at a glance. Nobody has to scroll to find where the counter changes.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">The Six Classic for-Loop Mistakes</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">1. The stray semicolon</span> (the all-time champion):</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++);</span> <span class="js-cm">// ← semicolon = empty body!{ printf("%d\n", i); // runs ONCE, after the loop: prints 6}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">2. Off-by-one:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><</span> <span class="js-num">5</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-cm">// prints 1 2 3 4 — NOT 1 2 3 4 5</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">< 5</code> stops <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">at</em> 5; <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;"><= 5</code> <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">includes</em> 5. When your loop count is wrong by exactly one, the comparison operator did it.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">3. Wrong update direction:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">10</span><span class="js-op">;</span>
<span class="js-id">i</span> <span class="js-op">>=</span> <span class="js-num">1</span><span class="js-op">;</span>
<span class="js-id">i</span><span class="js-op">++)</span> <span class="js-cm">// i grows AWAY from 1 — infinite loop!</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">4. Comma instead of semicolon in the header:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">,</span> <span class="js-id">i</span> <span class="js-op"><</span> <span class="js-num">5</span><span class="js-op">,</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-cm">// ✗ compile error — semicolons only</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">5. Modifying the counter inside the body:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-num">10</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span>
<span class="js-id">i</span> <span class="js-op">+=</span> <span class="js-num">2</span><span class="js-op">;</span> <span class="js-cm">// legal, but the loop now skips unpredictably</span>
<span class="js-op">}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">6. Looping with float counters:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">float</span> <span class="js-id">f</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">.</span>0f<span class="js-op">;</span>
<span class="js-id">f</span> <span class="js-op">!=</span> <span class="js-num">1</span><span class="js-op">.</span>0f<span class="js-op">;</span>
<span class="js-id">f</span> <span class="js-op">+=</span> <span class="js-num">0</span><span class="js-op">.</span>1f<span class="js-op">)</span> <span class="js-cm">// 0.1 isn't exact in binary...</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Floating-point rounding means <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">f</code> may never hit exactly <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">1.0</code> — infinite loop. Use integer counters; compute floats inside the body if needed.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">(Suggested image: "6 for-loop Mistakes" checklist graphic, consistent with the series)</em></p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">A Complete Example: Prime Number Checker</h2><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;">#<span class="js-id">include</span> <span class="js-op"><</span><span class="js-id">stdio</span><span class="js-op">.</span><span class="js-id">h</span><span class="js-op">></span>
<span class="js-id">int</span> <span class="js-id">main</span><span class="js-op">()</span> <span class="js-op">{</span>
<span class="js-id">int</span> <span class="js-id">num</span><span class="js-op">,</span> <span class="js-id">isPrime</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Enter a number: "</span><span class="js-op">);</span>
<span class="js-id">scanf</span><span class="js-op">(</span><span class="js-str">"%d"</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">num</span><span class="js-op">);</span>
<span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">num</span> <span class="js-op"><</span> <span class="js-num">2</span><span class="js-op">)</span> <span class="js-op">{</span>
<span class="js-id">isPrime</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">;</span>
<span class="js-op">}</span> <span class="js-kw">else</span> <span class="js-op">{</span>
<span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">2</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-id">num</span> <span class="js-op">/</span> <span class="js-num">2</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span>
<span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">num</span> <span class="js-op">%</span> <span class="js-id">i</span> <span class="js-op">==</span> <span class="js-num">0</span><span class="js-op">)</span> <span class="js-op">{</span>
<span class="js-id">isPrime</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">;</span>
<span class="js-kw">break</span><span class="js-op">;</span> <span class="js-cm">// found a divisor — no point checking further</span>
<span class="js-op">}</span>
<span class="js-op">}</span>
<span class="js-op">}</span>
<span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">isPrime</span><span class="js-op">)</span> <span class="js-op">{</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d is prime.\n"</span><span class="js-op">,</span> <span class="js-id">num</span><span class="js-op">);</span>
<span class="js-op">}</span> <span class="js-kw">else</span> <span class="js-op">{</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d is not prime.\n"</span><span class="js-op">,</span> <span class="js-id">num</span><span class="js-op">);</span>
<span class="js-op">}</span>
<span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;</span>
<span class="js-op">}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Sample Runs:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">Enter</span> <span class="js-id">a</span> <span class="js-id">number</span><span class="js-op">:</span> <span class="js-num">29</span>
<span class="js-num">29</span> <span class="js-id">is</span> <span class="js-id">prime</span><span class="js-op">.</span></code></pre></div></div></div><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">Enter</span> <span class="js-id">a</span> <span class="js-id">number</span><span class="js-op">:</span> <span class="js-num">30</span>
<span class="js-num">30</span> <span class="js-id">is</span> <span class="js-id">not</span> <span class="js-id">prime</span><span class="js-op">.</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Notice the loop design: we only check divisors up to <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">num / 2</code> (no larger divisor can possibly divide evenly), and <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">break</code> exits the instant we find one. That's the <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code> loop used thoughtfully — counted repetition with an early escape.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Final Thoughts</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">The <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code> loop earns its popularity through sheer clarity: one header line tells you where the loop starts, when it stops, and how it moves. Master the execution order — <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">init once, check before, body, update after</em> — and every <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">for</code> loop you'll ever read becomes transparent.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Practice priority: counting both directions, the sum program, then the star patterns until you can derive them from the "how many in row i?" question. Do that, and nested loops stop being scary — they become a tool you genuinely enjoy.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Next in the cluster: the <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">while</code> loop, where we drop the counter and let a condition run the show.</p>
Code Example
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += i;
}
printf("Sum of numbers 1 to 10 is: %d\
", sum);
return 0;
}Interview Question & Tips
A: Its scope is restricted strictly to the `for` loop block (introduced in C99); it does not exist after the loop terminates.
Q: What is the output of `for (int i = 0; i < 5; ++i)` vs `i++`?
A: Identical! The update expression is evaluated as an isolated statement after the body finishes.
Best Practices
This study reference for C for Loop: Syntax, Execution Steps, and Flowchart is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation: