Free AI web copilot to create summaries, insights and extended knowledge, download it at here
1953
Abstract
p;image=https%3A%2F%2Fplay.kotlinlang.org%2Fassets%2Fog-image.png&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=kotl" allowfullscreen="" frameborder="0" height="300" width="800">
</div>
</div>
</figure></iframe></div></div></figure><ol><li>Iterates over a range starting from 0 up to 3 (inclusive). Like <code>for (i=0; i<=3; ++i)</code> in other C-based languages.</li><li>Iterates over a range starting from 0 up to 3 (exclusive). Like the <code>for</code> loop in Python or like <code>for(i=0; i< 3; ++i)</code> in other C-based languages.</li><li>Iterates over a range with a custom increment step for consecutive elements.</li><li>Iterates over a range in <i>reverse</i> order</li></ol><p id="b300">Now, this syntax might seem like it’s awfully ad-hoc, but in time, you’ll find out that everything here is actually something you can do yourself, using <a href="https://readmedium.com/operators-6625ca0b8a63">operators</a> and <a href="https://readmedium.com/infix-functions-f2c328941939">infix functions</a>. The <code>..</code> and <code>in</code> are simply syntactic sugar for calls to the <a href="https://kotlinlang.org/docs/operator-overloading.html#arithmetic-operators">rangeTo</a> and <a href="https://kotlinlang.org/docs/operator-overloading.html#in-operator">contains</a> operators, respectively. But all in due time — don’t worry about it for now.</p><p id="e634"><code>Char</code> ranges are also supported out of the box:</p>
<figure id="9ee5">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2Fr1i-nUnxF&display_name=Kotlin+Playground&url=https%3A%2F%2Fpl.kotl.in%2Fr1i-nUnxF&image=https%3A%2F%2Fplay.kotlinlang.org%2Fassets%2Fog-image.png&key=a19fcc184b9711e1b4764040d3dc5c07
Options
&type=text%2Fhtml&schema=kotl" allowfullscreen="" frameborder="0" height="300" width="800">
</div>
</div>
</figure></iframe></div></div></figure><ol><li>Iterates over a char range in alphabetical order</li><li>Char ranges support <code>step</code> and <code>downTo</code> as well</li></ol><p id="a690">Ranges are also useful in <code>if</code> statements:</p>
<figure id="9395">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FjSV6shBdK&display_name=Kotlin+Playground&url=https%3A%2F%2Fpl.kotl.in%2FjSV6shBdK&image=https%3A%2F%2Fplay.kotlinlang.org%2Fassets%2Fog-image.png&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=kotl" allowfullscreen="" frameborder="0" height="300" width="800">
</div>
</div>
</figure></iframe></div></div></figure><ol><li>Checks if a value is in the range</li><li><code>!in</code> is the opposite of <code>in</code></li></ol><p id="5b53">More can be found in <a href="https://kotlinlang.org/docs/ranges.html">the docs</a>.</p><p id="5c38">Go back to the <a href="https://readmedium.com/conditional-expression-7fb52a02b767">Conditional Expression</a>, jump to the <a href="https://readmedium.com/table-of-contents-c52573cfa291">Table of Contents</a>, or continue to <a href="https://readmedium.com/triple-quoted-strings-adc99888ccb0">Triple-quoted Strings</a>.</p><figure id="8ecd"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*biBSB579iezsNvEQ_NMLBg.png"><figcaption><a href="https://www.etnetera.cz/prace-u-nas?utm_source=medium&utm_medium=GabrielShanahan&utm_campaign=KotlinPrimer&utm_content=join-our-team&utm_term=KotlinPrimer#pozice">Join me in Etnetera</a></figcaption></figure></article></body>