Jump statements are used when you want to interrupt or control the normal sequential flow of your program.
They help with:
🔄 Exiting loops early (
break)⏭ Skipping to the next iteration (
continue)🚀 Exiting functions and returning values (
return)⚠ Jumping unconditionally to another code block (
goto) — use with caution
🔴 break Statement
🧠 Purpose:
Used to break out of:
Loops (
for,while,do-while)switchcases
Once break is encountered, the control exits the loop/switch immediately and continues after it.
<div class="infographic-jsbreak">
<style>
.infographic-jsbreak {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--ok: #1a7f4e;
--ok-soft: #e3f5ec;
--warn: #b45309;
--warn-soft: #fdf0dc;
--display-font: 'Fraunces', Georgia, serif;
--body-font: 'Inter', -apple-system, sans-serif;
--mono-font: 'IBM Plex Mono', 'Courier New', monospace;
max-width: 820px;
margin: 0 auto;
box-sizing: border-box;
font-family: var(--body-font);
color: var(--ink);
background: var(--paper);
}
.infographic-jsbreak[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--ok: #5cd6a0;
--ok-soft: #16342a;
--warn: #e0a458;
--warn-soft: #3a2c14;
}
.infographic-jsbreak * { box-sizing: border-box; }
.infographic-jsbreak .ig-inner { padding: 1.75rem clamp(1.25rem, 5vw, 3rem) 2rem; }
.infographic-jsbreak .ig-title {
font-family: var(--display-font); font-size: clamp(1.4rem, 4.5vw, 1.9rem);
font-weight: 600; text-align: center; margin: 0 0 0.4rem;
}
.infographic-jsbreak .ig-code {
text-align: center; font-family: var(--mono-font); font-size: 0.8rem; color: var(--ink-soft);
margin: 0 0 1.75rem; line-height: 1.6;
}
.infographic-jsbreak .ig-code strong { color: var(--warn); }
.infographic-jsbreak .controls { display: flex; align-items: center; justify-content: center; gap: 0.6rem; flex-wrap: wrap; }
.infographic-jsbreak .ctrl-btn {
font: inherit; font-size: 0.82rem; font-weight: 600; border: 1px solid var(--line);
background: var(--paper-alt); color: var(--ink); padding: 0.45rem 1rem;
border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem;
}
.infographic-jsbreak .ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }
.infographic-jsbreak .ctrl-btn.primary { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.infographic-jsbreak .i-badge {
font-family: var(--mono-font); font-size: 0.85rem; font-weight: 700; color: var(--accent);
background: var(--accent-soft); padding: 0.45rem 0.9rem; border-radius: 999px;
}
.infographic-jsbreak .stage { margin-top: 1.5rem; display: flex; justify-content: center; }
.infographic-jsbreak .stage svg { width: 100%; max-width: 720px; height: auto; overflow: visible; }
.infographic-jsbreak .fc-shape { fill: var(--paper-alt); stroke: var(--line); stroke-width: 1.8; transition: fill 0.2s, stroke 0.2s; }
.infographic-jsbreak .fc-shape.reached-yes { fill: var(--accent-soft); stroke: var(--accent); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsbreak .fc-shape.reached-no { fill: var(--paper-alt); stroke: var(--accent); }
.infographic-jsbreak .fc-shape.reached-break { fill: var(--warn-soft); stroke: var(--warn); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsbreak .fc-block.reached { fill: var(--ok-soft); stroke: var(--ok); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsbreak .fc-pill { fill: var(--accent-soft); stroke: var(--accent); }
.infographic-jsbreak .fc-pill.reached { filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsbreak .fc-pill.reached-break { fill: var(--warn-soft); stroke: var(--warn); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsbreak .fc-text { font-family: var(--mono-font); font-size: 12px; fill: var(--ink); text-anchor: middle; }
.infographic-jsbreak .fc-text.on-pill { fill: var(--accent); font-weight: 700; }
.infographic-jsbreak .fc-text.on-block { font-weight: 700; }
.infographic-jsbreak .fc-mark { font-family: var(--mono-font); font-size: 13px; font-weight: 700; text-anchor: middle; }
.infographic-jsbreak .fc-mark.yes { fill: var(--accent); }
.infographic-jsbreak .fc-mark.no { fill: var(--ink-soft); }
.infographic-jsbreak .fc-mark.break { fill: var(--warn); }
.infographic-jsbreak .edge-label { font-family: var(--mono-font); font-size: 10px; fill: var(--ink-soft); text-anchor: middle; }
.infographic-jsbreak .edge-label.warn { fill: var(--warn); font-weight: 700; }
.infographic-jsbreak .fc-edge path { stroke: var(--line); stroke-width: 2; fill: none; transition: stroke 0.2s; }
.infographic-jsbreak .fc-edge polygon { fill: var(--line); transition: fill 0.2s; }
.infographic-jsbreak .fc-edge.is-active path { stroke: var(--accent); stroke-width: 2.5; }
.infographic-jsbreak .fc-edge.is-active polygon { fill: var(--accent); }
.infographic-jsbreak .fc-edge.is-break path { stroke: var(--warn); stroke-width: 2.5; }
.infographic-jsbreak .fc-edge.is-break polygon { fill: var(--warn); }
.infographic-jsbreak .junction { fill: var(--line); transition: fill 0.2s; }
.infographic-jsbreak .junction.is-active { fill: var(--accent); }
.infographic-jsbreak .junction.is-break { fill: var(--warn); }
.infographic-jsbreak .output {
margin-top: 1.5rem; text-align: center; font-family: var(--mono-font); font-size: 0.85rem;
color: var(--ink-soft); min-height: 1.4em;
}
.infographic-jsbreak .output strong { color: var(--ok); }
.infographic-jsbreak .caption {
text-align: center; font-size: 0.9rem; color: var(--ink-soft); margin-top: 0.6rem; min-height: 1.2em;
}
.infographic-jsbreak .caption strong { color: var(--ink); font-family: var(--mono-font); }
.infographic-jsbreak .caption strong.warn { color: var(--warn); }
@media (prefers-reduced-motion: reduce) {
.infographic-jsbreak *, .infographic-jsbreak *::before, .infographic-jsbreak *::after {
animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}
}
</style>
<div class="ig-inner">
<h2 class="ig-title">The break Statement</h2>
<p class="ig-code">for (let i = 1; i < 6; i++) {<br> if (i == 4) { <strong>break;</strong> }<br> console.log(i);<br>}</p>
<div class="controls">
<button class="ctrl-btn primary" id="playBtn">▶ Play</button>
<button class="ctrl-btn" id="restartBtn">⟲ Restart</button>
<span class="i-badge" id="iBadge">i = —</span>
</div>
<div class="stage">
<svg viewBox="0 0 770 420" xmlns="http://www.w3.org/2000/svg">
<!-- Start -->
<g id="n-start">
<rect class="fc-shape fc-pill" x="15" y="130" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="65" y="155">Start</text>
</g>
<!-- Start -> Init -->
<g class="fc-edge" id="e-start-init">
<path d="M115,150 L149,150"></path>
<polygon points="155,150 145,145 145,155"></polygon>
</g>
<!-- Init -->
<g id="n-init">
<rect class="fc-shape fc-block" x="155" y="125" width="130" height="50" rx="8"></rect>
<text class="fc-text on-block" x="220" y="155">let i = 1</text>
</g>
<!-- Init -> Condition1 -->
<g class="fc-edge" id="e-init-check1">
<path d="M285,150 L309,150"></path>
<polygon points="315,150 305,145 305,155"></polygon>
</g>
<!-- Condition 1: i < 6 -->
<g id="n-check1">
<polygon class="fc-shape" points="365,95 435,150 365,205 295,150"></polygon>
<text class="fc-text" x="365" y="146">i < 6</text>
<text class="fc-text" x="365" y="160">?</text>
<text class="fc-mark" id="mark-check1" x="400" y="115"></text>
</g>
<!-- Yes1 -> Break check -->
<g class="fc-edge" id="e-check1-yes">
<path d="M435,150 L459,150"></path>
<polygon points="465,150 455,145 455,155"></polygon>
</g>
<text class="edge-label" x="450" y="138">yes</text>
<!-- Break check: i == 4 -->
<g id="n-breakcheck">
<polygon class="fc-shape" points="535,95 605,150 535,205 465,150"></polygon>
<text class="fc-text" x="535" y="146">i == 4</text>
<text class="fc-text" x="535" y="160">?</text>
<text class="fc-mark" id="mark-breakcheck" x="570" y="115"></text>
</g>
<!-- Break check No -> Statement -->
<g class="fc-edge" id="e-breakcheck-no">
<path d="M605,150 L629,150"></path>
<polygon points="635,150 625,145 625,155"></polygon>
</g>
<text class="edge-label" x="620" y="138">no</text>
<g id="n-statement">
<rect class="fc-shape fc-block" x="635" y="125" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="695" y="155">log(i)</text>
</g>
<!-- Statement -> Increment -->
<g class="fc-edge" id="e-statement-inc">
<path d="M695,125 L695,84"></path>
<polygon points="695,78 690,88 700,88"></polygon>
</g>
<!-- Increment -->
<g id="n-increment">
<rect class="fc-shape fc-block" x="635" y="25" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="695" y="55">i++</text>
</g>
<!-- Increment -> Condition1 (loop back) -->
<g class="fc-edge" id="e-inc-check1">
<path d="M635,50 L365,50 L365,84"></path>
<polygon points="365,90 360,80 370,80"></polygon>
</g>
<!-- Break check Yes -> down -> junction (break!) -->
<g class="fc-edge" id="e-breakcheck-yes">
<path d="M535,205 L535,290 L365,290"></path>
</g>
<text class="edge-label warn" x="551" y="240">yes — break!</text>
<!-- Condition1 No -> junction (loop finished normally) -->
<g class="fc-edge" id="e-check1-no">
<path d="M365,205 L365,284"></path>
</g>
<text class="edge-label" x="381" y="240">no</text>
<!-- Junction -->
<circle class="junction" id="junction" cx="365" cy="290" r="4.5"></circle>
<!-- Junction -> End -->
<g class="fc-edge" id="e-junction-end">
<path d="M365,290 L365,334"></path>
<polygon points="365,340 360,330 370,330"></polygon>
</g>
<!-- End -->
<g id="n-end">
<rect class="fc-shape fc-pill" x="315" y="340" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="365" y="365">End</text>
</g>
</svg>
</div>
<p class="output" id="output"></p>
<p class="caption" id="caption">Press Play to run the loop.</p>
</div>
</div>
<script>
(function () {
const wrapper = document.currentScript.closest('.infographic-jsbreak')
|| document.querySelector('.infographic-jsbreak');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
const playBtn = wrapper.querySelector('#playBtn');
const restartBtn = wrapper.querySelector('#restartBtn');
const iBadge = wrapper.querySelector('#iBadge');
const output = wrapper.querySelector('#output');
const caption = wrapper.querySelector('#caption');
const nStart = wrapper.querySelector('#n-start .fc-pill');
const nInit = wrapper.querySelector('#n-init .fc-block');
const nCheck1 = wrapper.querySelector('#n-check1 .fc-shape');
const markCheck1 = wrapper.querySelector('#mark-check1');
const nBreakCheck = wrapper.querySelector('#n-breakcheck .fc-shape');
const markBreakCheck = wrapper.querySelector('#mark-breakcheck');
const nStatement = wrapper.querySelector('#n-statement .fc-block');
const nIncrement = wrapper.querySelector('#n-increment .fc-block');
const nEnd = wrapper.querySelector('#n-end .fc-pill');
const junction = wrapper.querySelector('#junction');
const eStartInit = wrapper.querySelector('#e-start-init');
const eInitCheck1 = wrapper.querySelector('#e-init-check1');
const eCheck1Yes = wrapper.querySelector('#e-check1-yes');
const eBreakcheckNo = wrapper.querySelector('#e-breakcheck-no');
const eStatementInc = wrapper.querySelector('#e-statement-inc');
const eIncCheck1 = wrapper.querySelector('#e-inc-check1');
const eBreakcheckYes = wrapper.querySelector('#e-breakcheck-yes');
const eCheck1No = wrapper.querySelector('#e-check1-no');
const eJunctionEnd = wrapper.querySelector('#e-junction-end');
const allNodes = [nStart, nInit, nCheck1, nBreakCheck, nStatement, nIncrement, nEnd];
const allEdges = [eStartInit, eInitCheck1, eCheck1Yes, eBreakcheckNo, eStatementInc, eIncCheck1, eBreakcheckYes, eCheck1No, eJunctionEnd];
function resetVisual() {
allNodes.forEach(n => n.classList.remove('reached', 'reached-yes', 'reached-no', 'reached-break'));
allEdges.forEach(e => e.classList.remove('is-active', 'is-break'));
junction.classList.remove('is-active', 'is-break');
markCheck1.textContent = ''; markCheck1.classList.remove('yes', 'no');
markBreakCheck.textContent = ''; markBreakCheck.classList.remove('yes', 'no', 'break');
}
let steps = [];
function buildSteps() {
steps = [];
steps.push({ edge: eStartInit });
steps.push({ node: nInit, setBadge: 1 });
steps.push({ edge: eInitCheck1 });
let i = 1;
let safety = 0;
while (safety++ < 20) {
const cond1 = i < 6;
steps.push({ check1: true, i, result: cond1 });
if (!cond1) {
steps.push({ edge: eCheck1No });
steps.push({ junctionStep: true, viaBreak: false });
steps.push({ edge: eJunctionEnd });
steps.push({ node: nEnd, done: true });
break;
}
steps.push({ edge: eCheck1Yes });
const isBreak = (i === 4);
steps.push({ breakcheck: true, i, result: isBreak });
if (isBreak) {
steps.push({ edge: eBreakcheckYes });
steps.push({ junctionStep: true, viaBreak: true });
steps.push({ edge: eJunctionEnd });
steps.push({ node: nEnd, done: true, viaBreak: true });
break;
}
steps.push({ edge: eBreakcheckNo });
steps.push({ node: nStatement, i, log: i });
steps.push({ edge: eStatementInc });
steps.push({ node: nIncrement, setBadge: i + 1 });
steps.push({ edge: eIncCheck1 });
i++;
}
}
buildSteps();
let idx = -1;
let timer = null;
let logged = [];
function applyStep(step) {
resetVisual();
nStart.classList.add('reached');
if (step.edge) {
step.edge.classList.add(step.edge === eBreakcheckYes || (step.edge === eJunctionEnd && wasBreak) ? 'is-break' : 'is-active');
}
if (step.junctionStep) {
junction.classList.add(step.viaBreak ? 'is-break' : 'is-active');
wasBreak = step.viaBreak;
}
if (step.node) {
step.node.classList.add(step.viaBreak ? 'reached-break' : 'reached');
if (step.setBadge !== undefined) iBadge.textContent = `i = ${step.setBadge}`;
if (step.log !== undefined) {
logged.push(step.log);
output.innerHTML = `console: <strong>${logged.join(', ')}</strong>`;
}
if (step.done) {
caption.innerHTML = step.viaBreak
? `loop exited early via <strong class="warn">break</strong>`
: `loop finished normally — condition is false`;
}
}
if (step.check1) {
nCheck1.classList.add(step.result ? 'reached-yes' : 'reached-no');
markCheck1.textContent = step.result ? '✓' : '✗';
markCheck1.classList.add(step.result ? 'yes' : 'no');
iBadge.textContent = `i = ${step.i}`;
if (!step.result) caption.textContent = `i = ${step.i} → false, exit the loop`;
else caption.textContent = `i = ${step.i} → true, check for break`;
}
if (step.breakcheck) {
nBreakCheck.classList.add(step.result ? 'reached-break' : 'reached-no');
markBreakCheck.textContent = step.result ? '✓' : '✗';
markBreakCheck.classList.add(step.result ? 'break' : 'no');
iBadge.textContent = `i = ${step.i}`;
caption.innerHTML = step.result
? `i = ${step.i} → <strong class="warn">break!</strong> exit loop immediately`
: `i = ${step.i} → not 4, keep going`;
}
}
let wasBreak = false;
function stop() {
clearInterval(timer);
timer = null;
playBtn.textContent = '▶ Play';
}
function advance() {
idx++;
if (idx >= steps.length) {
stop();
return;
}
applyStep(steps[idx]);
if (idx >= steps.length - 1) stop();
}
function play() {
if (timer) { stop(); return; }
if (idx >= steps.length - 1) restart(false);
playBtn.textContent = '⏸ Pause';
timer = setInterval(advance, 850);
advance();
}
function restart(clearBadge = true) {
stop();
idx = -1;
logged = [];
wasBreak = false;
output.textContent = '';
resetVisual();
if (clearBadge) {
iBadge.textContent = 'i = —';
caption.textContent = 'Press Play to run the loop.';
}
}
playBtn.addEventListener('click', play);
restartBtn.addEventListener('click', () => restart(true));
restart(true);
})();
</script>📌 Syntax:
break✅ Example 1: break in for loop
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
if (i == 5)
break;
printf("%d ", i);
}
return 0;1 2 3 4🔎 Explanation:
The loop breaks as soon as i == 5. Remaining values (5–10) are skipped.
✅ Example 2: break in switch statement
int day = 3;
switch(day) {
case 1: printf("Monday"); break;
case 2: printf("Tuesday"); break;
case 3: printf("Wednesday"); break;
default: printf("Invalid");Wednesday🔎 Explanation:
If you forget break, C will execute all remaining cases — this is called fallthrough.
🔵 continue Statement
🧠 Purpose:
Used to skip the current iteration and jump to the next iteration of the loop.
Only used inside loops (
for,while,do-while)It does not exit the loop — only skips one cycle
<div class="infographic-jscontinue">
<style>
.infographic-jscontinue {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--ok: #1a7f4e;
--ok-soft: #e3f5ec;
--warn: #b45309;
--warn-soft: #fdf0dc;
--display-font: 'Fraunces', Georgia, serif;
--body-font: 'Inter', -apple-system, sans-serif;
--mono-font: 'IBM Plex Mono', 'Courier New', monospace;
max-width: 820px;
margin: 0 auto;
box-sizing: border-box;
font-family: var(--body-font);
color: var(--ink);
background: var(--paper);
}
.infographic-jscontinue[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--ok: #5cd6a0;
--ok-soft: #16342a;
--warn: #e0a458;
--warn-soft: #3a2c14;
}
.infographic-jscontinue * { box-sizing: border-box; }
.infographic-jscontinue .ig-inner { padding: 1.75rem clamp(1.25rem, 5vw, 3rem) 2rem; }
.infographic-jscontinue .ig-title {
font-family: var(--display-font); font-size: clamp(1.4rem, 4.5vw, 1.9rem);
font-weight: 600; text-align: center; margin: 0 0 0.4rem;
}
.infographic-jscontinue .ig-code {
text-align: center; font-family: var(--mono-font); font-size: 0.8rem; color: var(--ink-soft);
margin: 0 0 1.75rem; line-height: 1.6;
}
.infographic-jscontinue .ig-code strong { color: var(--warn); }
.infographic-jscontinue .controls { display: flex; align-items: center; justify-content: center; gap: 0.6rem; flex-wrap: wrap; }
.infographic-jscontinue .ctrl-btn {
font: inherit; font-size: 0.82rem; font-weight: 600; border: 1px solid var(--line);
background: var(--paper-alt); color: var(--ink); padding: 0.45rem 1rem;
border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem;
}
.infographic-jscontinue .ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }
.infographic-jscontinue .ctrl-btn.primary { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.infographic-jscontinue .i-badge {
font-family: var(--mono-font); font-size: 0.85rem; font-weight: 700; color: var(--accent);
background: var(--accent-soft); padding: 0.45rem 0.9rem; border-radius: 999px;
}
.infographic-jscontinue .stage { margin-top: 1.5rem; display: flex; justify-content: center; }
.infographic-jscontinue .stage svg { width: 100%; max-width: 720px; height: auto; overflow: visible; }
.infographic-jscontinue .fc-shape { fill: var(--paper-alt); stroke: var(--line); stroke-width: 1.8; transition: fill 0.2s, stroke 0.2s; }
.infographic-jscontinue .fc-shape.reached-yes { fill: var(--accent-soft); stroke: var(--accent); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jscontinue .fc-shape.reached-no { fill: var(--paper-alt); stroke: var(--accent); }
.infographic-jscontinue .fc-shape.reached-skip { fill: var(--warn-soft); stroke: var(--warn); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jscontinue .fc-block.reached { fill: var(--ok-soft); stroke: var(--ok); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jscontinue .fc-block.reached-skip { fill: var(--warn-soft); stroke: var(--warn); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jscontinue .fc-pill { fill: var(--accent-soft); stroke: var(--accent); }
.infographic-jscontinue .fc-pill.reached { filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jscontinue .fc-text { font-family: var(--mono-font); font-size: 12px; fill: var(--ink); text-anchor: middle; }
.infographic-jscontinue .fc-text.on-pill { fill: var(--accent); font-weight: 700; }
.infographic-jscontinue .fc-text.on-block { font-weight: 700; }
.infographic-jscontinue .fc-mark { font-family: var(--mono-font); font-size: 13px; font-weight: 700; text-anchor: middle; }
.infographic-jscontinue .fc-mark.yes { fill: var(--accent); }
.infographic-jscontinue .fc-mark.no { fill: var(--ink-soft); }
.infographic-jscontinue .fc-mark.skip { fill: var(--warn); }
.infographic-jscontinue .edge-label { font-family: var(--mono-font); font-size: 10px; fill: var(--ink-soft); text-anchor: middle; }
.infographic-jscontinue .edge-label.warn { fill: var(--warn); font-weight: 700; }
.infographic-jscontinue .fc-edge path { stroke: var(--line); stroke-width: 2; fill: none; transition: stroke 0.2s; }
.infographic-jscontinue .fc-edge polygon { fill: var(--line); transition: fill 0.2s; }
.infographic-jscontinue .fc-edge.is-active path { stroke: var(--accent); stroke-width: 2.5; }
.infographic-jscontinue .fc-edge.is-active polygon { fill: var(--accent); }
.infographic-jscontinue .fc-edge.is-skip path { stroke: var(--warn); stroke-width: 2.5; }
.infographic-jscontinue .fc-edge.is-skip polygon { fill: var(--warn); }
.infographic-jscontinue .output {
margin-top: 1.5rem; text-align: center; font-family: var(--mono-font); font-size: 0.85rem;
color: var(--ink-soft); min-height: 1.4em;
}
.infographic-jscontinue .output strong { color: var(--ok); }
.infographic-jscontinue .caption {
text-align: center; font-size: 0.9rem; color: var(--ink-soft); margin-top: 0.6rem; min-height: 1.2em;
}
.infographic-jscontinue .caption strong { color: var(--ink); font-family: var(--mono-font); }
.infographic-jscontinue .caption strong.warn { color: var(--warn); }
@media (prefers-reduced-motion: reduce) {
.infographic-jscontinue *, .infographic-jscontinue *::before, .infographic-jscontinue *::after {
animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}
}
</style>
<div class="ig-inner">
<h2 class="ig-title">The continue Statement</h2>
<p class="ig-code">for (let i = 0; i < 10; i++) {<br> if (i % 2 == 0) { <strong>continue;</strong> }<br> console.log(i);<br>}</p>
<div class="controls">
<button class="ctrl-btn primary" id="playBtn">▶ Play</button>
<button class="ctrl-btn" id="restartBtn">⟲ Restart</button>
<span class="i-badge" id="iBadge">i = —</span>
</div>
<div class="stage">
<svg viewBox="0 0 770 350" xmlns="http://www.w3.org/2000/svg">
<!-- Start -->
<g id="n-start">
<rect class="fc-shape fc-pill" x="15" y="130" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="65" y="155">Start</text>
</g>
<!-- Start -> Init -->
<g class="fc-edge" id="e-start-init">
<path d="M115,150 L149,150"></path>
<polygon points="155,150 145,145 145,155"></polygon>
</g>
<!-- Init -->
<g id="n-init">
<rect class="fc-shape fc-block" x="155" y="125" width="130" height="50" rx="8"></rect>
<text class="fc-text on-block" x="220" y="155">let i = 0</text>
</g>
<!-- Init -> Condition1 -->
<g class="fc-edge" id="e-init-check1">
<path d="M285,150 L309,150"></path>
<polygon points="315,150 305,145 305,155"></polygon>
</g>
<!-- Condition 1: i < 10 -->
<g id="n-check1">
<polygon class="fc-shape" points="365,95 435,150 365,205 295,150"></polygon>
<text class="fc-text" x="365" y="146">i < 10</text>
<text class="fc-text" x="365" y="160">?</text>
<text class="fc-mark" id="mark-check1" x="400" y="115"></text>
</g>
<!-- Yes1 -> Continue check -->
<g class="fc-edge" id="e-check1-yes">
<path d="M435,150 L459,150"></path>
<polygon points="465,150 455,145 455,155"></polygon>
</g>
<text class="edge-label" x="450" y="138">yes</text>
<!-- Continue check: i % 2 == 0 -->
<g id="n-continuecheck">
<polygon class="fc-shape" points="535,95 605,150 535,205 465,150"></polygon>
<text class="fc-text" x="535" y="141">i % 2</text>
<text class="fc-text" x="535" y="155">== 0 ?</text>
<text class="fc-mark" id="mark-continuecheck" x="570" y="115"></text>
</g>
<!-- Continue check No (odd) -> Statement -->
<g class="fc-edge" id="e-cc-no">
<path d="M605,150 L629,150"></path>
<polygon points="635,150 625,145 625,155"></polygon>
</g>
<text class="edge-label" x="620" y="138">no</text>
<g id="n-statement">
<rect class="fc-shape fc-block" x="635" y="125" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="695" y="155">log(i)</text>
</g>
<!-- Statement -> Increment -->
<g class="fc-edge" id="e-statement-inc">
<path d="M695,125 L695,84"></path>
<polygon points="695,78 690,88 700,88"></polygon>
</g>
<!-- Increment -->
<g id="n-increment">
<rect class="fc-shape fc-block" x="635" y="25" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="695" y="55">i++</text>
</g>
<!-- Continue check Yes (even) -> down and back to Condition1, skipping Statement/Increment display -->
<g class="fc-edge" id="e-cc-yes">
<path d="M535,205 L535,245 L365,245 L365,211"></path>
<polygon points="365,205 360,211 370,211"></polygon>
</g>
<text class="edge-label warn" x="450" y="260">yes — continue!</text>
<!-- Increment -> Condition1 (loop back) -->
<g class="fc-edge" id="e-inc-check1">
<path d="M635,50 L365,50 L365,84"></path>
<polygon points="365,90 360,80 370,80"></polygon>
</g>
<!-- Condition1 No -> End -->
<g class="fc-edge" id="e-check1-no">
<path d="M365,205 L365,274"></path>
<polygon points="365,280 360,270 370,270"></polygon>
</g>
<text class="edge-label" x="381" y="240">no</text>
<!-- End -->
<g id="n-end">
<rect class="fc-shape fc-pill" x="315" y="280" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="365" y="305">End</text>
</g>
</svg>
</div>
<p class="output" id="output"></p>
<p class="caption" id="caption">Press Play to run the loop.</p>
</div>
</div>
<script>
(function () {
const wrapper = document.currentScript.closest('.infographic-jscontinue')
|| document.querySelector('.infographic-jscontinue');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
const playBtn = wrapper.querySelector('#playBtn');
const restartBtn = wrapper.querySelector('#restartBtn');
const iBadge = wrapper.querySelector('#iBadge');
const output = wrapper.querySelector('#output');
const caption = wrapper.querySelector('#caption');
const nStart = wrapper.querySelector('#n-start .fc-pill');
const nInit = wrapper.querySelector('#n-init .fc-block');
const nCheck1 = wrapper.querySelector('#n-check1 .fc-shape');
const markCheck1 = wrapper.querySelector('#mark-check1');
const nContinueCheck = wrapper.querySelector('#n-continuecheck .fc-shape');
const markContinueCheck = wrapper.querySelector('#mark-continuecheck');
const nStatement = wrapper.querySelector('#n-statement .fc-block');
const nIncrement = wrapper.querySelector('#n-increment .fc-block');
const nEnd = wrapper.querySelector('#n-end .fc-pill');
const eStartInit = wrapper.querySelector('#e-start-init');
const eInitCheck1 = wrapper.querySelector('#e-init-check1');
const eCheck1Yes = wrapper.querySelector('#e-check1-yes');
const eCcNo = wrapper.querySelector('#e-cc-no');
const eStatementInc = wrapper.querySelector('#e-statement-inc');
const eIncCheck1 = wrapper.querySelector('#e-inc-check1');
const eCcYes = wrapper.querySelector('#e-cc-yes');
const eCheck1No = wrapper.querySelector('#e-check1-no');
const allNodes = [nStart, nInit, nCheck1, nContinueCheck, nStatement, nIncrement, nEnd];
const allEdges = [eStartInit, eInitCheck1, eCheck1Yes, eCcNo, eStatementInc, eIncCheck1, eCcYes, eCheck1No];
function resetVisual() {
allNodes.forEach(n => n.classList.remove('reached', 'reached-yes', 'reached-no', 'reached-skip'));
allEdges.forEach(e => e.classList.remove('is-active', 'is-skip'));
markCheck1.textContent = ''; markCheck1.classList.remove('yes', 'no');
markContinueCheck.textContent = ''; markContinueCheck.classList.remove('yes', 'no', 'skip');
}
let steps = [];
function buildSteps() {
steps = [];
steps.push({ edge: eStartInit });
steps.push({ node: nInit, setBadge: 0 });
steps.push({ edge: eInitCheck1 });
let i = 0;
let safety = 0;
while (safety++ < 40) {
const cond1 = i < 10;
steps.push({ check1: true, i, result: cond1 });
if (!cond1) {
steps.push({ edge: eCheck1No });
steps.push({ node: nEnd, done: true });
break;
}
steps.push({ edge: eCheck1Yes });
const isEven = (i % 2 === 0);
steps.push({ ccheck: true, i, result: isEven });
if (isEven) {
steps.push({ edge: eCcYes, skip: true });
} else {
steps.push({ edge: eCcNo });
steps.push({ node: nStatement, i, log: i });
steps.push({ edge: eStatementInc });
steps.push({ node: nIncrement, setBadge: i + 1 });
steps.push({ edge: eIncCheck1 });
}
i++;
}
}
buildSteps();
let idx = -1;
let timer = null;
let logged = [];
function applyStep(step) {
resetVisual();
nStart.classList.add('reached');
if (step.edge) {
step.edge.classList.add(step.skip ? 'is-skip' : 'is-active');
}
if (step.node) {
if (step.skip) {
step.node.classList.add('reached-skip');
} else {
step.node.classList.add('reached');
}
if (step.setBadge !== undefined) iBadge.textContent = `i = ${step.setBadge}`;
if (step.log !== undefined) {
logged.push(step.log);
output.innerHTML = `console: <strong>${logged.join(', ')}</strong>`;
}
if (step.done) {
caption.textContent = 'Loop finished — condition is false.';
}
}
if (step.check1) {
nCheck1.classList.add(step.result ? 'reached-yes' : 'reached-no');
markCheck1.textContent = step.result ? '✓' : '✗';
markCheck1.classList.add(step.result ? 'yes' : 'no');
iBadge.textContent = `i = ${step.i}`;
caption.textContent = step.result
? `i = ${step.i} → true, check for even`
: `i = ${step.i} → false, exit the loop`;
}
if (step.ccheck) {
nContinueCheck.classList.add(step.result ? 'reached-skip' : 'reached-no');
markContinueCheck.textContent = step.result ? '✓' : '✗';
markContinueCheck.classList.add(step.result ? 'skip' : 'no');
iBadge.textContent = `i = ${step.i}`;
caption.innerHTML = step.result
? `i = ${step.i} → even, <strong class="warn">continue!</strong> jump back to the condition`
: `i = ${step.i} → odd, log it`;
}
}
function stop() {
clearInterval(timer);
timer = null;
playBtn.textContent = '▶ Play';
}
function advance() {
idx++;
if (idx >= steps.length) {
stop();
return;
}
applyStep(steps[idx]);
if (idx >= steps.length - 1) stop();
}
function play() {
if (timer) { stop(); return; }
if (idx >= steps.length - 1) restart(false);
playBtn.textContent = '⏸ Pause';
timer = setInterval(advance, 700);
advance();
}
function restart(clearBadge = true) {
stop();
idx = -1;
logged = [];
output.textContent = '';
resetVisual();
if (clearBadge) {
iBadge.textContent = 'i = —';
caption.textContent = 'Press Play to run the loop.';
}
}
playBtn.addEventListener('click', play);
restartBtn.addEventListener('click', () => restart(true));
restart(true);
})();
</script>📌 Syntax:
continue✅ Example: Skipping multiples of 3
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
if (i % 3 == 0)
continue;
printf("%d ", i);
}
return 0;
}1 2 4 5 7 8 10🔎 Explanation:
Whenever i is a multiple of 3, continue skips the printf() for that iteration.
🌀 goto Statement (⚠ Not recommended)
🧠 Purpose:
goto is used to jump unconditionally to another point in the code marked by a label.
Using goto makes code harder to read, trace, and debug. Avoid it unless absolutely needed (e.g., in low-level programming or for breaking out of nested loops).
<div class="infographic-cgoto">
<style>
.infographic-cgoto {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--ok: #1a7f4e;
--ok-soft: #e3f5ec;
--warn: #b45309;
--warn-soft: #fdf0dc;
--display-font: 'Fraunces', Georgia, serif;
--body-font: 'Inter', -apple-system, sans-serif;
--mono-font: 'IBM Plex Mono', 'Courier New', monospace;
max-width: 820px;
margin: 0 auto;
box-sizing: border-box;
font-family: var(--body-font);
color: var(--ink);
background: var(--paper);
}
.infographic-cgoto[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--ok: #5cd6a0;
--ok-soft: #16342a;
--warn: #e0a458;
--warn-soft: #3a2c14;
}
.infographic-cgoto * { box-sizing: border-box; }
.infographic-cgoto .ig-inner { padding: 1.75rem clamp(1.25rem, 5vw, 3rem) 2rem; }
.infographic-cgoto .ig-title {
font-family: var(--display-font); font-size: clamp(1.4rem, 4.5vw, 1.9rem);
font-weight: 600; text-align: center; margin: 0 0 0.4rem;
}
.infographic-cgoto .ig-code {
text-align: center; font-family: var(--mono-font); font-size: 0.78rem; color: var(--ink-soft);
margin: 0 0 1.75rem; line-height: 1.6;
}
.infographic-cgoto .ig-code strong { color: var(--warn); }
.infographic-cgoto .controls { display: flex; align-items: center; justify-content: center; gap: 0.6rem; flex-wrap: wrap; }
.infographic-cgoto .ctrl-btn {
font: inherit; font-size: 0.82rem; font-weight: 600; border: 1px solid var(--line);
background: var(--paper-alt); color: var(--ink); padding: 0.45rem 1rem;
border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem;
}
.infographic-cgoto .ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }
.infographic-cgoto .ctrl-btn.primary { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.infographic-cgoto .i-badge {
font-family: var(--mono-font); font-size: 0.85rem; font-weight: 700; color: var(--accent);
background: var(--accent-soft); padding: 0.45rem 0.9rem; border-radius: 999px;
}
.infographic-cgoto .stage { margin-top: 1.5rem; display: flex; justify-content: center; }
.infographic-cgoto .stage svg { width: 100%; max-width: 760px; height: auto; overflow: visible; }
.infographic-cgoto .fc-shape { fill: var(--paper-alt); stroke: var(--line); stroke-width: 1.8; transition: fill 0.2s, stroke 0.2s; }
.infographic-cgoto .fc-shape.reached-yes { fill: var(--warn-soft); stroke: var(--warn); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-cgoto .fc-shape.reached-no { fill: var(--paper-alt); stroke: var(--accent); }
.infographic-cgoto .fc-block.reached { fill: var(--ok-soft); stroke: var(--ok); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-cgoto .fc-block.reached-jump { fill: var(--warn-soft); stroke: var(--warn); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-cgoto .fc-pill { fill: var(--accent-soft); stroke: var(--accent); }
.infographic-cgoto .fc-pill.reached { filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-cgoto .fc-text { font-family: var(--mono-font); font-size: 12px; fill: var(--ink); text-anchor: middle; }
.infographic-cgoto .fc-text.on-pill { fill: var(--accent); font-weight: 700; }
.infographic-cgoto .fc-text.on-block { font-weight: 700; }
.infographic-cgoto .fc-text.on-jump { fill: var(--warn); font-weight: 700; }
.infographic-cgoto .fc-mark { font-family: var(--mono-font); font-size: 13px; font-weight: 700; text-anchor: middle; }
.infographic-cgoto .fc-mark.yes { fill: var(--warn); }
.infographic-cgoto .fc-mark.no { fill: var(--ink-soft); }
.infographic-cgoto .edge-label { font-family: var(--mono-font); font-size: 10px; fill: var(--ink-soft); text-anchor: middle; }
.infographic-cgoto .edge-label.warn { fill: var(--warn); font-weight: 700; }
.infographic-cgoto .fc-edge path { stroke: var(--line); stroke-width: 2; fill: none; transition: stroke 0.2s; }
.infographic-cgoto .fc-edge polygon { fill: var(--line); transition: fill 0.2s; }
.infographic-cgoto .fc-edge.is-active path { stroke: var(--accent); stroke-width: 2.5; }
.infographic-cgoto .fc-edge.is-active polygon { fill: var(--accent); }
.infographic-cgoto .fc-edge.is-jump path { stroke: var(--warn); stroke-width: 2.5; stroke-dasharray: 5 4; }
.infographic-cgoto .fc-edge.is-jump polygon { fill: var(--warn); }
.infographic-cgoto .output {
margin-top: 1.5rem; text-align: center; font-family: var(--mono-font); font-size: 0.85rem;
color: var(--ink-soft); min-height: 1.4em;
}
.infographic-cgoto .output strong { color: var(--ok); }
.infographic-cgoto .caption {
text-align: center; font-size: 0.9rem; color: var(--ink-soft); margin-top: 0.6rem; min-height: 1.2em;
}
.infographic-cgoto .caption strong { color: var(--ink); font-family: var(--mono-font); }
.infographic-cgoto .caption strong.warn { color: var(--warn); }
@media (prefers-reduced-motion: reduce) {
.infographic-cgoto *, .infographic-cgoto *::before, .infographic-cgoto *::after {
animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}
}
</style>
<div class="ig-inner">
<h2 class="ig-title">The goto Statement</h2>
<p class="ig-code">i = 0;<br><strong>start:</strong> if (i >= 5) <strong>goto end;</strong><br> printf("%d\n", i);<br> i++;<br> <strong>goto start;</strong><br><strong>end:</strong> printf("Done");</p>
<div class="controls">
<button class="ctrl-btn primary" id="playBtn">▶ Play</button>
<button class="ctrl-btn" id="restartBtn">⟲ Restart</button>
<span class="i-badge" id="iBadge">i = —</span>
</div>
<div class="stage">
<svg viewBox="0 0 770 360" xmlns="http://www.w3.org/2000/svg">
<!-- Start -->
<g id="n-start">
<rect class="fc-shape fc-pill" x="15" y="130" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="65" y="155">Start</text>
</g>
<g class="fc-edge" id="e-start-init">
<path d="M115,150 L149,150"></path>
<polygon points="155,150 145,145 145,155"></polygon>
</g>
<!-- Init -->
<g id="n-init">
<rect class="fc-shape fc-block" x="155" y="125" width="130" height="50" rx="8"></rect>
<text class="fc-text on-block" x="220" y="155">i = 0;</text>
</g>
<g class="fc-edge" id="e-init-check">
<path d="M285,150 L309,150"></path>
<polygon points="315,150 305,145 305,155"></polygon>
</g>
<!-- Condition: i >= 5 ? (this is "start:") -->
<g id="n-check">
<polygon class="fc-shape" points="365,95 435,150 365,205 295,150"></polygon>
<text class="fc-text" x="365" y="146">i >= 5</text>
<text class="fc-text" x="365" y="160">?</text>
<text class="fc-mark" id="mark-check" x="400" y="115"></text>
</g>
<text class="edge-label warn" x="330" y="78">start:</text>
<!-- Yes -> goto end; -->
<g class="fc-edge" id="e-check-yes">
<path d="M435,150 L459,150"></path>
<polygon points="465,150 455,145 455,155"></polygon>
</g>
<text class="edge-label" x="450" y="138">yes</text>
<g id="n-gotoend">
<rect class="fc-shape fc-block" x="465" y="125" width="130" height="50" rx="8"></rect>
<text class="fc-text on-jump" x="530" y="155">goto end;</text>
</g>
<!-- goto end; -> End (dashed jump) -->
<g class="fc-edge" id="e-gotoend-end">
<path d="M530,175 L530,280 L415,280"></path>
<polygon points="409,280 419,275 419,285"></polygon>
</g>
<!-- No -> printf -->
<g class="fc-edge" id="e-check-no">
<path d="M365,205 L365,245 L635,245 L635,181"></path>
<polygon points="635,175 630,185 640,185"></polygon>
</g>
<text class="edge-label" x="381" y="240">no</text>
<g id="n-print">
<rect class="fc-shape fc-block" x="635" y="125" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="695" y="155">printf(i)</text>
</g>
<g class="fc-edge" id="e-print-inc">
<path d="M695,125 L695,84"></path>
<polygon points="695,78 690,88 700,88"></polygon>
</g>
<!-- Increment -->
<g id="n-increment">
<rect class="fc-shape fc-block" x="635" y="25" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="695" y="55">i++;</text>
</g>
<g class="fc-edge" id="e-inc-gotostart">
<path d="M635,50 L561,50"></path>
<polygon points="555,50 565,45 565,55"></polygon>
</g>
<!-- goto start; -->
<g id="n-gotostart">
<rect class="fc-shape fc-block" x="430" y="25" width="125" height="50" rx="8"></rect>
<text class="fc-text on-jump" x="492" y="55">goto start;</text>
</g>
<!-- goto start; -> Condition (dashed jump, loop back) -->
<g class="fc-edge" id="e-gotostart-check">
<path d="M430,50 L365,50 L365,84"></path>
<polygon points="365,90 360,80 370,80"></polygon>
</g>
<!-- End -->
<g id="n-end">
<rect class="fc-shape fc-pill" x="315" y="280" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="365" y="305">End</text>
</g>
</svg>
</div>
<p class="output" id="output"></p>
<p class="caption" id="caption">Press Play to run the loop.</p>
</div>
</div>
<script>
(function () {
const wrapper = document.currentScript.closest('.infographic-cgoto')
|| document.querySelector('.infographic-cgoto');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
const playBtn = wrapper.querySelector('#playBtn');
const restartBtn = wrapper.querySelector('#restartBtn');
const iBadge = wrapper.querySelector('#iBadge');
const output = wrapper.querySelector('#output');
const caption = wrapper.querySelector('#caption');
const nStart = wrapper.querySelector('#n-start .fc-pill');
const nInit = wrapper.querySelector('#n-init .fc-block');
const nCheck = wrapper.querySelector('#n-check .fc-shape');
const markCheck = wrapper.querySelector('#mark-check');
const nGotoEnd = wrapper.querySelector('#n-gotoend .fc-block');
const nPrint = wrapper.querySelector('#n-print .fc-block');
const nIncrement = wrapper.querySelector('#n-increment .fc-block');
const nGotoStart = wrapper.querySelector('#n-gotostart .fc-block');
const nEnd = wrapper.querySelector('#n-end .fc-pill');
const eStartInit = wrapper.querySelector('#e-start-init');
const eInitCheck = wrapper.querySelector('#e-init-check');
const eCheckYes = wrapper.querySelector('#e-check-yes');
const eGotoEndEnd = wrapper.querySelector('#e-gotoend-end');
const eCheckNo = wrapper.querySelector('#e-check-no');
const ePrintInc = wrapper.querySelector('#e-print-inc');
const eIncGotoStart = wrapper.querySelector('#e-inc-gotostart');
const eGotoStartCheck = wrapper.querySelector('#e-gotostart-check');
const allNodes = [nStart, nInit, nCheck, nGotoEnd, nPrint, nIncrement, nGotoStart, nEnd];
const allEdges = [eStartInit, eInitCheck, eCheckYes, eGotoEndEnd, eCheckNo, ePrintInc, eIncGotoStart, eGotoStartCheck];
function resetVisual() {
allNodes.forEach(n => n.classList.remove('reached', 'reached-yes', 'reached-no', 'reached-jump'));
allEdges.forEach(e => e.classList.remove('is-active', 'is-jump'));
markCheck.textContent = ''; markCheck.classList.remove('yes', 'no');
}
let steps = [];
function buildSteps() {
steps = [];
steps.push({ edge: eStartInit });
steps.push({ node: nInit, setBadge: 0 });
steps.push({ edge: eInitCheck });
let i = 0;
let safety = 0;
while (safety++ < 40) {
const done = i >= 5;
steps.push({ check: true, i, result: done });
if (done) {
steps.push({ edge: eCheckYes });
steps.push({ node: nGotoEnd, jump: true, i });
steps.push({ edge: eGotoEndEnd, jump: true });
steps.push({ node: nEnd, finished: true });
break;
}
steps.push({ edge: eCheckNo });
steps.push({ node: nPrint, log: i });
steps.push({ edge: ePrintInc });
steps.push({ node: nIncrement, setBadge: i + 1 });
steps.push({ edge: eIncGotoStart });
steps.push({ node: nGotoStart, jump: true, i: i + 1 });
steps.push({ edge: eGotoStartCheck, jump: true });
i++;
}
}
buildSteps();
let idx = -1;
let timer = null;
let logged = [];
function applyStep(step) {
resetVisual();
nStart.classList.add('reached');
if (step.edge) {
step.edge.classList.add(step.jump ? 'is-jump' : 'is-active');
}
if (step.node) {
if (step.jump) {
step.node.classList.add('reached-jump');
} else {
step.node.classList.add('reached');
}
if (step.setBadge !== undefined) iBadge.textContent = `i = ${step.setBadge}`;
if (step.log !== undefined) {
logged.push(step.log);
output.innerHTML = `output: <strong>${logged.join(' ')}</strong>`;
}
if (step.finished) {
output.innerHTML += (logged.length ? ' ' : '') + '<strong>Done</strong>';
caption.textContent = 'i reached 5 — goto end; jumped straight past the loop.';
}
}
if (step.check) {
nCheck.classList.add(step.result ? 'reached-yes' : 'reached-no');
markCheck.textContent = step.result ? '✓' : '✗';
markCheck.classList.add(step.result ? 'yes' : 'no');
iBadge.textContent = `i = ${step.i}`;
caption.textContent = step.result
? `i = ${step.i} → true, goto end;`
: `i = ${step.i} → false, keep going`;
}
}
function stop() {
clearInterval(timer);
timer = null;
playBtn.textContent = '▶ Play';
}
function advance() {
idx++;
if (idx >= steps.length) {
stop();
return;
}
applyStep(steps[idx]);
if (idx >= steps.length - 1) stop();
}
function play() {
if (timer) { stop(); return; }
if (idx >= steps.length - 1) restart(false);
playBtn.textContent = '⏸ Pause';
timer = setInterval(advance, 750);
advance();
}
function restart(clearBadge = true) {
stop();
idx = -1;
logged = [];
output.textContent = '';
resetVisual();
if (clearBadge) {
iBadge.textContent = 'i = —';
caption.textContent = 'Press Play to run the loop.';
}
}
playBtn.addEventListener('click', play);
restartBtn.addEventListener('click', () => restart(true));
restart(true);
})();
</script>📌 Syntax:
goto label_name; // somewhere else in code
label_name: // code block⚠️ Example:
#include <stdio.h>
int main() {
int num = 5;
if (num == 5)
goto skip;
printf("This will be skipped");
skip:
printf("You jumped to here!");
return 0;
}You jumped to here!🔎 Explanation: goto bypasses the printf("This will be skipped"); line.
🔚 return Statement
🧠 Purpose:
Ends the execution of a function
Can return a value to the caller (or nothing if the function returns
void)
<div class="infographic-creturn">
<style>
.infographic-creturn {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--ok: #1a7f4e;
--ok-soft: #e3f5ec;
--warn: #b45309;
--warn-soft: #fdf0dc;
--display-font: 'Fraunces', Georgia, serif;
--body-font: 'Inter', -apple-system, sans-serif;
--mono-font: 'IBM Plex Mono', 'Courier New', monospace;
max-width: 820px;
margin: 0 auto;
box-sizing: border-box;
font-family: var(--body-font);
color: var(--ink);
background: var(--paper);
}
.infographic-creturn[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--ok: #5cd6a0;
--ok-soft: #16342a;
--warn: #e0a458;
--warn-soft: #3a2c14;
}
.infographic-creturn * { box-sizing: border-box; }
.infographic-creturn .ig-inner { padding: 1.75rem clamp(1.25rem, 5vw, 3rem) 2rem; }
.infographic-creturn .ig-title {
font-family: var(--display-font); font-size: clamp(1.4rem, 4.5vw, 1.9rem);
font-weight: 600; text-align: center; margin: 0 0 0.4rem;
}
.infographic-creturn .ig-code {
text-align: center; font-family: var(--mono-font); font-size: 0.76rem; color: var(--ink-soft);
margin: 0 0 1.75rem; line-height: 1.6;
}
.infographic-creturn .ig-code strong { color: var(--warn); }
.infographic-creturn .controls { display: flex; align-items: center; justify-content: center; gap: 0.6rem; flex-wrap: wrap; }
.infographic-creturn .ctrl-btn {
font: inherit; font-size: 0.82rem; font-weight: 600; border: 1px solid var(--line);
background: var(--paper-alt); color: var(--ink); padding: 0.45rem 1rem;
border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem;
}
.infographic-creturn .ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }
.infographic-creturn .ctrl-btn.primary { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.infographic-creturn .i-badge {
font-family: var(--mono-font); font-size: 0.85rem; font-weight: 700; color: var(--accent);
background: var(--accent-soft); padding: 0.45rem 0.9rem; border-radius: 999px;
}
.infographic-creturn .stage { margin-top: 1.5rem; display: flex; justify-content: center; }
.infographic-creturn .stage svg { width: 100%; max-width: 780px; height: auto; overflow: visible; }
.infographic-creturn .fc-shape { fill: var(--paper-alt); stroke: var(--line); stroke-width: 1.8; transition: fill 0.2s, stroke 0.2s; }
.infographic-creturn .fc-shape.reached-yes { fill: var(--ok-soft); stroke: var(--ok); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-creturn .fc-shape.reached-no { fill: var(--paper-alt); stroke: var(--accent); }
.infographic-creturn .fc-block.reached { fill: var(--ok-soft); stroke: var(--ok); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-creturn .fc-block.reached-jump { fill: var(--warn-soft); stroke: var(--warn); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-creturn .fc-pill { fill: var(--accent-soft); stroke: var(--accent); }
.infographic-creturn .fc-pill.reached { filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-creturn .fc-text { font-family: var(--mono-font); font-size: 12px; fill: var(--ink); text-anchor: middle; }
.infographic-creturn .fc-text.on-pill { fill: var(--accent); font-weight: 700; }
.infographic-creturn .fc-text.on-block { font-weight: 700; }
.infographic-creturn .fc-text.on-return { fill: var(--ok); font-weight: 700; }
.infographic-creturn .fc-text.on-return.miss { fill: var(--warn); }
.infographic-creturn .fc-mark { font-family: var(--mono-font); font-size: 13px; font-weight: 700; text-anchor: middle; }
.infographic-creturn .fc-mark.yes { fill: var(--ok); }
.infographic-creturn .fc-mark.no { fill: var(--ink-soft); }
.infographic-creturn .edge-label { font-family: var(--mono-font); font-size: 10px; fill: var(--ink-soft); text-anchor: middle; }
.infographic-creturn .edge-label.warn { fill: var(--warn); font-weight: 700; }
.infographic-creturn .fc-edge path { stroke: var(--line); stroke-width: 2; fill: none; transition: stroke 0.2s; }
.infographic-creturn .fc-edge polygon { fill: var(--line); transition: fill 0.2s; }
.infographic-creturn .fc-edge.is-active path { stroke: var(--accent); stroke-width: 2.5; }
.infographic-creturn .fc-edge.is-active polygon { fill: var(--accent); }
.infographic-creturn .fc-edge.is-jump path { stroke: var(--warn); stroke-width: 2.5; stroke-dasharray: 5 4; }
.infographic-creturn .fc-edge.is-jump polygon { fill: var(--warn); }
.infographic-creturn .fc-edge.is-jump-ok path { stroke: var(--ok); stroke-width: 2.5; stroke-dasharray: 5 4; }
.infographic-creturn .fc-edge.is-jump-ok polygon { fill: var(--ok); }
.infographic-creturn .output {
margin-top: 1.5rem; text-align: center; font-family: var(--mono-font); font-size: 0.85rem;
color: var(--ink-soft); min-height: 1.4em;
}
.infographic-creturn .output strong { color: var(--ok); }
.infographic-creturn .caption {
text-align: center; font-size: 0.9rem; color: var(--ink-soft); margin-top: 0.6rem; min-height: 1.2em;
}
.infographic-creturn .caption strong { color: var(--ink); font-family: var(--mono-font); }
.infographic-creturn .caption strong.warn { color: var(--warn); }
.infographic-creturn .caption strong.ok { color: var(--ok); }
@media (prefers-reduced-motion: reduce) {
.infographic-creturn *, .infographic-creturn *::before, .infographic-creturn *::after {
animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}
}
</style>
<div class="ig-inner">
<h2 class="ig-title">The return Statement</h2>
<p class="ig-code">int findFirstEven(int arr[], int n) {<br> for (int i = 0; i < n; i++) {<br> if (arr[i] % 2 == 0) { <strong>return arr[i];</strong> }<br> }<br> <strong>return -1;</strong><br>}</p>
<div class="controls">
<button class="ctrl-btn primary" id="playBtn">▶ Play</button>
<button class="ctrl-btn" id="restartBtn">⟲ Restart</button>
<span class="i-badge" id="iBadge">i = —</span>
</div>
<div class="stage">
<svg viewBox="0 0 800 380" xmlns="http://www.w3.org/2000/svg">
<!-- Start -->
<g id="n-start">
<rect class="fc-shape fc-pill" x="15" y="130" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="65" y="155">Start</text>
</g>
<g class="fc-edge" id="e-start-init">
<path d="M115,150 L149,150"></path>
<polygon points="155,150 145,145 145,155"></polygon>
</g>
<!-- Init -->
<g id="n-init">
<rect class="fc-shape fc-block" x="155" y="125" width="130" height="50" rx="8"></rect>
<text class="fc-text on-block" x="220" y="155">i = 0;</text>
</g>
<g class="fc-edge" id="e-init-check1">
<path d="M285,150 L309,150"></path>
<polygon points="315,150 305,145 305,155"></polygon>
</g>
<!-- Condition 1: i < n -->
<g id="n-check1">
<polygon class="fc-shape" points="365,95 435,150 365,205 295,150"></polygon>
<text class="fc-text" x="365" y="146">i < n</text>
<text class="fc-text" x="365" y="160">?</text>
<text class="fc-mark" id="mark-check1" x="400" y="115"></text>
</g>
<g class="fc-edge" id="e-check1-yes">
<path d="M435,150 L459,150"></path>
<polygon points="465,150 455,145 455,155"></polygon>
</g>
<text class="edge-label" x="450" y="138">yes</text>
<!-- Condition 2: arr[i] % 2 == 0 -->
<g id="n-check2">
<polygon class="fc-shape" points="535,95 605,150 535,205 465,150"></polygon>
<text class="fc-text" x="535" y="141">arr[i] % 2</text>
<text class="fc-text" x="535" y="155">== 0 ?</text>
<text class="fc-mark" id="mark-check2" x="570" y="115"></text>
</g>
<g class="fc-edge" id="e-check2-yes">
<path d="M605,150 L629,150"></path>
<polygon points="635,150 625,145 625,155"></polygon>
</g>
<text class="edge-label" x="620" y="138">yes</text>
<!-- return arr[i]; -->
<g id="n-returnfound">
<rect class="fc-shape fc-block" x="635" y="125" width="130" height="50" rx="8"></rect>
<text class="fc-text on-return" x="700" y="155">return arr[i];</text>
</g>
<!-- return arr[i]; -> End (jump, ok color) -->
<g class="fc-edge" id="e-returnfound-end">
<path d="M700,175 L700,325 L421,325"></path>
<polygon points="415,325 425,320 425,330"></polygon>
</g>
<!-- Condition2 no -> Increment -->
<g class="fc-edge" id="e-check2-no">
<path d="M535,205 L535,245 L790,245 L790,50 L761,50"></path>
<polygon points="755,50 765,45 765,55"></polygon>
</g>
<text class="edge-label" x="551" y="222">no</text>
<!-- Increment -->
<g id="n-increment">
<rect class="fc-shape fc-block" x="635" y="25" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="695" y="55">i++;</text>
</g>
<!-- Increment -> Condition1 (loop back) -->
<g class="fc-edge" id="e-inc-check1">
<path d="M635,50 L365,50 L365,84"></path>
<polygon points="365,90 360,80 370,80"></polygon>
</g>
<!-- Condition1 no -> return -1; -->
<g class="fc-edge" id="e-check1-no">
<path d="M365,205 L365,229"></path>
<polygon points="365,235 360,225 370,225"></polygon>
</g>
<text class="edge-label" x="381" y="222">no</text>
<g id="n-returnmiss">
<rect class="fc-shape fc-block" x="300" y="235" width="130" height="42" rx="8"></rect>
<text class="fc-text on-return miss" x="365" y="261">return -1;</text>
</g>
<!-- return -1; -> End -->
<g class="fc-edge" id="e-returnmiss-end">
<path d="M365,277 L365,299"></path>
<polygon points="365,305 360,295 370,295"></polygon>
</g>
<!-- End -->
<g id="n-end">
<rect class="fc-shape fc-pill" x="315" y="305" width="100" height="40" rx="20"></rect>
<text class="fc-text on-pill" x="365" y="330">End</text>
</g>
</svg>
</div>
<p class="output" id="output"></p>
<p class="caption" id="caption">Press Play to run the function.</p>
</div>
</div>
<script>
(function () {
const wrapper = document.currentScript.closest('.infographic-creturn')
|| document.querySelector('.infographic-creturn');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
const playBtn = wrapper.querySelector('#playBtn');
const restartBtn = wrapper.querySelector('#restartBtn');
const iBadge = wrapper.querySelector('#iBadge');
const output = wrapper.querySelector('#output');
const caption = wrapper.querySelector('#caption');
const nStart = wrapper.querySelector('#n-start .fc-pill');
const nInit = wrapper.querySelector('#n-init .fc-block');
const nCheck1 = wrapper.querySelector('#n-check1 .fc-shape');
const markCheck1 = wrapper.querySelector('#mark-check1');
const nCheck2 = wrapper.querySelector('#n-check2 .fc-shape');
const markCheck2 = wrapper.querySelector('#mark-check2');
const nReturnFound = wrapper.querySelector('#n-returnfound .fc-block');
const nIncrement = wrapper.querySelector('#n-increment .fc-block');
const nReturnMiss = wrapper.querySelector('#n-returnmiss .fc-block');
const nEnd = wrapper.querySelector('#n-end .fc-pill');
const eStartInit = wrapper.querySelector('#e-start-init');
const eInitCheck1 = wrapper.querySelector('#e-init-check1');
const eCheck1Yes = wrapper.querySelector('#e-check1-yes');
const eCheck2Yes = wrapper.querySelector('#e-check2-yes');
const eReturnFoundEnd = wrapper.querySelector('#e-returnfound-end');
const eCheck2No = wrapper.querySelector('#e-check2-no');
const eIncCheck1 = wrapper.querySelector('#e-inc-check1');
const eCheck1No = wrapper.querySelector('#e-check1-no');
const eReturnMissEnd = wrapper.querySelector('#e-returnmiss-end');
const allNodes = [nStart, nInit, nCheck1, nCheck2, nReturnFound, nIncrement, nReturnMiss, nEnd];
const allEdges = [eStartInit, eInitCheck1, eCheck1Yes, eCheck2Yes, eReturnFoundEnd, eCheck2No, eIncCheck1, eCheck1No, eReturnMissEnd];
function resetVisual() {
allNodes.forEach(n => n.classList.remove('reached', 'reached-yes', 'reached-no', 'reached-jump'));
allEdges.forEach(e => e.classList.remove('is-active', 'is-jump', 'is-jump-ok'));
markCheck1.textContent = ''; markCheck1.classList.remove('yes', 'no');
markCheck2.textContent = ''; markCheck2.classList.remove('yes', 'no');
}
const ARR = [7, 9, 4, 3, 8];
const N = ARR.length;
let steps = [];
function buildSteps() {
steps = [];
steps.push({ edge: eStartInit });
steps.push({ node: nInit, setBadge: 0 });
steps.push({ edge: eInitCheck1 });
let i = 0;
let safety = 0;
while (safety++ < 40) {
const cond1 = i < N;
steps.push({ check1: true, i, result: cond1 });
if (!cond1) {
steps.push({ edge: eCheck1No });
steps.push({ node: nReturnMiss, miss: true });
steps.push({ edge: eReturnMissEnd });
steps.push({ node: nEnd, finished: true, found: false });
break;
}
steps.push({ edge: eCheck1Yes });
const val = ARR[i];
const isEven = val % 2 === 0;
steps.push({ check2: true, i, val, result: isEven });
if (isEven) {
steps.push({ edge: eCheck2Yes });
steps.push({ node: nReturnFound, found: true, val });
steps.push({ edge: eReturnFoundEnd, ok: true });
steps.push({ node: nEnd, finished: true, found: true, val });
break;
}
steps.push({ edge: eCheck2No });
steps.push({ node: nIncrement, setBadge: i + 1 });
steps.push({ edge: eIncCheck1 });
i++;
}
}
buildSteps();
let idx = -1;
let timer = null;
function applyStep(step) {
resetVisual();
nStart.classList.add('reached');
if (step.edge) {
step.edge.classList.add(step.ok ? 'is-jump-ok' : (step.edge === eCheck1No || step.edge === eReturnMissEnd || step.edge === eReturnFoundEnd ? 'is-jump' : 'is-active'));
}
if (step.node) {
if (step.miss || step.found) {
step.node.classList.add('reached-jump');
} else {
step.node.classList.add('reached');
}
if (step.setBadge !== undefined) iBadge.textContent = `i = ${step.setBadge}`;
if (step.found && step.val !== undefined && !step.finished) {
caption.innerHTML = `arr[i] = ${step.val} is even → <strong class="ok">return ${step.val};</strong> — exits the function now`;
}
if (step.miss && !step.finished) {
caption.innerHTML = `Loop finished with no match → <strong class="warn">return -1;</strong>`;
}
if (step.finished) {
output.innerHTML = step.found
? `function returns: <strong>${step.val}</strong>`
: `function returns: <strong>-1</strong>`;
caption.textContent = step.found
? 'return immediately exits the whole function — the loop never finishes.'
: 'No even number found — falls through to the final return.';
}
}
if (step.check1) {
nCheck1.classList.add(step.result ? 'reached-yes' : 'reached-no');
markCheck1.textContent = step.result ? '✓' : '✗';
markCheck1.classList.add(step.result ? 'yes' : 'no');
iBadge.textContent = `i = ${step.i}`;
caption.textContent = step.result
? `i = ${step.i} → true, check arr[i]`
: `i = ${step.i} → false, loop is over`;
}
if (step.check2) {
nCheck2.classList.add(step.result ? 'reached-yes' : 'reached-no');
markCheck2.textContent = step.result ? '✓' : '✗';
markCheck2.classList.add(step.result ? 'yes' : 'no');
iBadge.textContent = `i = ${step.i}`;
caption.textContent = step.result
? `arr[${step.i}] = ${step.val} → even`
: `arr[${step.i}] = ${step.val} → odd, keep looking`;
}
}
function stop() {
clearInterval(timer);
timer = null;
playBtn.textContent = '▶ Play';
}
function advance() {
idx++;
if (idx >= steps.length) {
stop();
return;
}
applyStep(steps[idx]);
if (idx >= steps.length - 1) stop();
}
function play() {
if (timer) { stop(); return; }
if (idx >= steps.length - 1) restart(false);
playBtn.textContent = '⏸ Pause';
timer = setInterval(advance, 750);
advance();
}
function restart(clearBadge = true) {
stop();
idx = -1;
output.textContent = '';
resetVisual();
if (clearBadge) {
iBadge.textContent = 'i = —';
caption.textContent = 'Press Play to run the function.';
}
}
playBtn.addEventListener('click', play);
restartBtn.addEventListener('click', () => restart(true));
restart(true);
})();
</script>📌 Syntax:
return; // for void functions
return value; // for value-returning functions✅ Example 1: Returning from main()
#include <stdio.h>
int main() {
printf("Hello\\n");
return 0;
}🔎 return 0; indicates the program finished successfully.
✅ Example 2: Return from a function
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(5, 3);
printf("%d", result); // Output: 8
}🔁 Bonus: break vs continue vs return vs goto
Statement | Purpose | Works In | Effect |
|---|---|---|---|
| Exit loop/switch | Loops, | Stops the loop |
| Skip current iteration | Loops | Skips to next cycle |
| Exit a function | Functions | Ends function, returns control/value |
| Jump to label | Anywhere | Jumps to labeled line (bad practice) |