45 lines
No EOL
2.4 KiB
HTML
45 lines
No EOL
2.4 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>while — Ludic</title>
|
||
<meta name="description" content="Loop as long as a condition holds, re-checking it before each pass.">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#control">Control flow</a> <span>›</span> <span class="here">while</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-keyword">keyword</span>
|
||
<h1 id="top">while</h1>
|
||
</div>
|
||
<code class="sig">while cond { … }</code>
|
||
<div class="desc"><p>A <code>while</code> loop re-evaluates its condition before every pass and runs the body as long as it stays true, so it is the tool when the number of iterations is not known up front. As with <code>if</code>, the condition needs no parentheses and the braces are required. <code>break</code> leaves the loop immediately and <code>continue</code> jumps to the next condition check. When you are simply counting over a fixed range, prefer the numeric <code>for i in a .. b</code> loop, which is clearer and binds a fresh index for you; reach for <code>while</code> when the step or the stopping test is irregular.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Countdown {
|
||
var fuse: int = 5
|
||
var elapsed_frames: int = 0
|
||
|
||
handler Tick phase Update {
|
||
elapsed_frames = elapsed_frames + 1
|
||
while fuse > 0 and elapsed_frames % 60 == 0 {
|
||
fuse = fuse - 1
|
||
elapsed_frames = elapsed_frames + 1
|
||
}
|
||
}
|
||
|
||
handler DrawWorld phase Render {
|
||
Screen.clear(Color.MidnightBlue)
|
||
Screen.draw_number(x: 8, y: 8, value: fuse, color: Color.Crimson, scale: 3)
|
||
Screen.show()
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |