|
| 1 | +<!DOCTYPE HTML> |
| 2 | +<html lang="en" class="sidebar-visible no-js oranda-dark"> |
| 3 | + <head> |
| 4 | + <!-- Book generated using mdBook --> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <title>Conditionals - The PooLang Book</title> |
| 7 | + |
| 8 | + |
| 9 | + <!-- Custom HTML head --> |
| 10 | + |
| 11 | + <meta name="description" content=""> |
| 12 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 13 | + <meta name="theme-color" content="#ffffff" /> |
| 14 | + |
| 15 | + <link rel="icon" href="../favicon.svg"> |
| 16 | + <link rel="shortcut icon" href="../favicon.png"> |
| 17 | + <link rel="stylesheet" href="../css/variables.css"> |
| 18 | + <link rel="stylesheet" href="../css/general.css"> |
| 19 | + <link rel="stylesheet" href="../css/chrome.css"> |
| 20 | + <link rel="stylesheet" href="../css/print.css" media="print"> |
| 21 | + |
| 22 | + <!-- Fonts --> |
| 23 | + <link rel="stylesheet" href="../FontAwesome/css/font-awesome.css"> |
| 24 | + <link rel="stylesheet" href="../fonts/fonts.css"> |
| 25 | + |
| 26 | + <!-- Highlight.js Stylesheets --> |
| 27 | + <link rel="stylesheet" href="../highlight.css"> |
| 28 | + <link rel="stylesheet" href="../tomorrow-night.css"> |
| 29 | + <link rel="stylesheet" href="../ayu-highlight.css"> |
| 30 | + <link rel="stylesheet" href="../oranda-highlight.css"> |
| 31 | + |
| 32 | + <!-- Custom theme stylesheets --> |
| 33 | + |
| 34 | + </head> |
| 35 | + <body> |
| 36 | + <div id="body-container"> |
| 37 | + <!-- Provide site root to javascript --> |
| 38 | + <script> |
| 39 | + var path_to_root = "../"; |
| 40 | + var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "oranda-dark" : "oranda-dark"; |
| 41 | + </script> |
| 42 | + |
| 43 | + <!-- Work around some values being stored in localStorage wrapped in quotes --> |
| 44 | + <script> |
| 45 | + try { |
| 46 | + var theme = localStorage.getItem('orandamdbook-theme'); |
| 47 | + var sidebar = localStorage.getItem('mdbook-sidebar'); |
| 48 | + |
| 49 | + if (theme.startsWith('"') && theme.endsWith('"')) { |
| 50 | + localStorage.setItem('orandamdbook-theme', theme.slice(1, theme.length - 1)); |
| 51 | + } |
| 52 | + |
| 53 | + if (sidebar.startsWith('"') && sidebar.endsWith('"')) { |
| 54 | + localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1)); |
| 55 | + } |
| 56 | + } catch (e) { } |
| 57 | + </script> |
| 58 | + |
| 59 | + <!-- Set the theme before any content is loaded, prevents flash --> |
| 60 | + <script> |
| 61 | + var theme; |
| 62 | + try { theme = localStorage.getItem('orandamdbook-theme'); } catch(e) { } |
| 63 | + if (theme === null || theme === undefined) { theme = default_theme; } |
| 64 | + var html = document.querySelector('html'); |
| 65 | + html.classList.remove('no-js') |
| 66 | + html.classList.remove('oranda-dark') |
| 67 | + html.classList.add(theme); |
| 68 | + html.classList.add('js'); |
| 69 | + </script> |
| 70 | + |
| 71 | + <!-- Hide / unhide sidebar before it is displayed --> |
| 72 | + <script> |
| 73 | + var html = document.querySelector('html'); |
| 74 | + var sidebar = 'hidden'; |
| 75 | + if (document.body.clientWidth >= 1080) { |
| 76 | + try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { } |
| 77 | + sidebar = sidebar || 'visible'; |
| 78 | + } |
| 79 | + html.classList.remove('sidebar-visible'); |
| 80 | + html.classList.add("sidebar-" + sidebar); |
| 81 | + </script> |
| 82 | + |
| 83 | + <nav id="sidebar" class="sidebar" aria-label="Table of contents"> |
| 84 | + <div class="sidebar-scrollbox"> |
| 85 | + <ol class="chapter"><li class="chapter-item expanded affix "><a href="../introduction.html">Introduction</a></li><li class="chapter-item expanded affix "><a href="../getting_started.html">Getting Started</a></li><li class="chapter-item expanded "><div><strong aria-hidden="true">1.</strong> Syntax Guide</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="../syntax/variables.html"><strong aria-hidden="true">1.1.</strong> Variables & Types</a></li><li class="chapter-item expanded "><a href="../syntax/operators.html"><strong aria-hidden="true">1.2.</strong> Operators & Math</a></li><li class="chapter-item expanded "><a href="../syntax/comments.html"><strong aria-hidden="true">1.3.</strong> Comments</a></li></ol></li><li class="chapter-item expanded "><div><strong aria-hidden="true">2.</strong> Control Flow</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="../control_flow/conditionals.html" class="active"><strong aria-hidden="true">2.1.</strong> Conditionals</a></li><li class="chapter-item expanded "><a href="../control_flow/loops.html"><strong aria-hidden="true">2.2.</strong> Loops</a></li></ol></li><li class="chapter-item expanded "><a href="../functions.html"><strong aria-hidden="true">3.</strong> Functions</a></li><li class="chapter-item expanded "><a href="../std.html"><strong aria-hidden="true">4.</strong> Standard Library</a></li><li class="chapter-item expanded "><div><strong aria-hidden="true">5.</strong> Internal Architecture</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="../internals/lexer.html"><strong aria-hidden="true">5.1.</strong> Lexer</a></li><li class="chapter-item expanded "><a href="../internals/parser.html"><strong aria-hidden="true">5.2.</strong> Parser</a></li><li class="chapter-item expanded "><a href="../internals/interpreter.html"><strong aria-hidden="true">5.3.</strong> Interpreter</a></li></ol></li></ol> |
| 86 | + </div> |
| 87 | + <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> |
| 88 | + </nav> |
| 89 | + |
| 90 | + <div id="page-wrapper" class="page-wrapper"> |
| 91 | + |
| 92 | + <div class="page"> |
| 93 | + <div id="menu-bar-hover-placeholder"></div> |
| 94 | + <div id="menu-bar" class="menu-bar sticky bordered"> |
| 95 | + <div class="left-buttons"> |
| 96 | + <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar"> |
| 97 | + <i class="fa fa-bars"></i> |
| 98 | + </button> |
| 99 | + <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list"> |
| 100 | + <i class="fa fa-paint-brush"></i> |
| 101 | + </button> |
| 102 | + <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu"> |
| 103 | + <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li> |
| 104 | + <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li> |
| 105 | + <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li> |
| 106 | + <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li> |
| 107 | + <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li> |
| 108 | + <li role="none"><button role="menuitem" class="theme" id="oranda-dark">Axo Dark</button></li> |
| 109 | + <li role="none"><button role="menuitem" class="theme" id="oranda-light">Axo Light</button></li> |
| 110 | + |
| 111 | + </ul> |
| 112 | + <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar"> |
| 113 | + <i class="fa fa-search"></i> |
| 114 | + </button> |
| 115 | + </div> |
| 116 | + |
| 117 | + <h1 class="menu-title">The PooLang Book</h1> |
| 118 | + |
| 119 | + <div class="right-buttons"> |
| 120 | + <a href="../print.html" title="Print this book" aria-label="Print this book"> |
| 121 | + <i id="print-button" class="fa fa-print"></i> |
| 122 | + </a> |
| 123 | + |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + |
| 127 | + <div id="search-wrapper" class="hidden"> |
| 128 | + <form id="searchbar-outer" class="searchbar-outer"> |
| 129 | + <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header"> |
| 130 | + </form> |
| 131 | + <div id="searchresults-outer" class="searchresults-outer hidden"> |
| 132 | + <div id="searchresults-header" class="searchresults-header"></div> |
| 133 | + <ul id="searchresults"> |
| 134 | + </ul> |
| 135 | + </div> |
| 136 | + </div> |
| 137 | + |
| 138 | + <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM --> |
| 139 | + <script> |
| 140 | + document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible'); |
| 141 | + document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible'); |
| 142 | + Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) { |
| 143 | + link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1); |
| 144 | + }); |
| 145 | + </script> |
| 146 | + |
| 147 | + <div id="content" class="content"> |
| 148 | + <main> |
| 149 | + <h1 id="conditionals"><a class="header" href="#conditionals">Conditionals</a></h1> |
| 150 | +<p>PooLang uses <code>if</code>, <code>elif</code>, and <code>else</code> to control the flow of execution based on boolean conditions.</p> |
| 151 | +<h2 id="if-statements"><a class="header" href="#if-statements">If Statements</a></h2> |
| 152 | +<p>The simplest form is a single <code>if</code> block:</p> |
| 153 | +<pre><code class="language-poo">if x > 10 { |
| 154 | + pout("x is large"); |
| 155 | +} |
| 156 | +</code></pre> |
| 157 | +<h2 id="if-else"><a class="header" href="#if-else">If-Else</a></h2> |
| 158 | +<p>You can provide an alternative path using <code>else</code>:</p> |
| 159 | +<pre><code class="language-poo">if x > 10 { |
| 160 | + pout("x is large"); |
| 161 | +} else { |
| 162 | + pout("x is small"); |
| 163 | +} |
| 164 | +</code></pre> |
| 165 | +<h2 id="elif-else-if"><a class="header" href="#elif-else-if">Elif (Else If)</a></h2> |
| 166 | +<p>For multiple conditions, use <code>elif</code>:</p> |
| 167 | +<pre><code class="language-poo">if x > 100 { |
| 168 | + pout("Huge"); |
| 169 | +} elif x > 10 { |
| 170 | + pout("Large"); |
| 171 | +} else { |
| 172 | + pout("Small"); |
| 173 | +} |
| 174 | +</code></pre> |
| 175 | +<h2 id="scoping"><a class="header" href="#scoping">Scoping</a></h2> |
| 176 | +<p>Variables declared inside a conditional block are scoped to that block and are not accessible outside.</p> |
| 177 | +<pre><code class="language-poo">if true { |
| 178 | + poo temp << 1; |
| 179 | +} |
| 180 | +# temp is no longer accessible here |
| 181 | +</code></pre> |
| 182 | + |
| 183 | + </main> |
| 184 | + |
| 185 | + <nav class="nav-wrapper" aria-label="Page navigation"> |
| 186 | + <!-- Mobile navigation buttons --> |
| 187 | + <a rel="prev" href="../syntax/comments.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left"> |
| 188 | + <i class="fa fa-angle-left"></i> |
| 189 | + </a> |
| 190 | + |
| 191 | + <a rel="next" href="../control_flow/loops.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> |
| 192 | + <i class="fa fa-angle-right"></i> |
| 193 | + </a> |
| 194 | + |
| 195 | + <div style="clear: both"></div> |
| 196 | + </nav> |
| 197 | + </div> |
| 198 | + </div> |
| 199 | + |
| 200 | + <nav class="nav-wide-wrapper" aria-label="Page navigation"> |
| 201 | + <a rel="prev" href="../syntax/comments.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left"> |
| 202 | + <i class="fa fa-angle-left"></i> |
| 203 | + </a> |
| 204 | + |
| 205 | + <a rel="next" href="../control_flow/loops.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> |
| 206 | + <i class="fa fa-angle-right"></i> |
| 207 | + </a> |
| 208 | + </nav> |
| 209 | + |
| 210 | + </div> |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + <script> |
| 216 | + window.playground_copyable = true; |
| 217 | + </script> |
| 218 | + |
| 219 | + |
| 220 | + <script src="../elasticlunr.min.js"></script> |
| 221 | + <script src="../mark.min.js"></script> |
| 222 | + <script src="../searcher.js"></script> |
| 223 | + |
| 224 | + <script src="../clipboard.min.js"></script> |
| 225 | + <script src="../highlight.js"></script> |
| 226 | + <script src="../book.js"></script> |
| 227 | + |
| 228 | + <!-- Custom JS scripts --> |
| 229 | + |
| 230 | + |
| 231 | + </div> |
| 232 | + </body> |
| 233 | +</html> |
0 commit comments