<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Coding on Colebot Blog</title><link>https://blog.colebot.com/tags/coding/</link><description>Recent content in Coding on Colebot Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 14 Nov 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://blog.colebot.com/tags/coding/index.xml" rel="self" type="application/rss+xml"/><item><title>Iterate forwards or backwards in a for loop</title><link>https://blog.colebot.com/posts/forward-backward-loop/</link><pubDate>Tue, 14 Nov 2023 00:00:00 +0000</pubDate><guid>https://blog.colebot.com/posts/forward-backward-loop/</guid><description>&lt;p&gt;It is trivial to write a for loop that counts upwards or that counts downwards,&#10;but what if you want to go upwards some of the time and downwards the rest of&#10;the time? Sure, you could use a function and switch between two different for&#10;loops each with the same function inside, but that’s not quite as elegant as&#10;what I’m about to show you today.&lt;/p&gt;&#10;&lt;p&gt;Normally, to count upwards, you start your loop at 0 and count up to the final&#10;element of the array. To count downwards, you start at the final element of the&#10;array and count down to 0. For this loop, though, we will always start at 0 and&#10;count either up or down. If we count up, we’re done after that. But if we count&#10;down, we end up with negative values for &lt;code&gt;i&lt;/code&gt;, which aren’t any good. That’s why&#10;we create a new value of &lt;code&gt;ix&lt;/code&gt;, which is offset upwards by one less than the&#10;array length only if we are counting downwards. We use this value of &lt;code&gt;ix&lt;/code&gt;&#10;wherever we would normally use &lt;code&gt;i&lt;/code&gt; inside the loop.&lt;/p&gt;</description></item><item><title>Javascript Async/Await Simplified</title><link>https://blog.colebot.com/posts/javascript-async-await/</link><pubDate>Fri, 08 Sep 2023 00:00:00 +0000</pubDate><guid>https://blog.colebot.com/posts/javascript-async-await/</guid><description>&lt;p&gt;For a long time, I’ve been confused about Async/Await syntax in JavaScript. I’d&#10;heard that these keywords were just syntactical sugar on top of Promises, but I&#10;didn’t know how exactly they worked. Well, I finally get it now, and it’s a lot&#10;simpler than I thought!&lt;/p&gt;&#10;&lt;h2 id="promises"&gt;Promises&lt;/h2&gt;&#10;&lt;p&gt;Promises on their own already help greatly with writing asynchronous code. Pass&#10;in a function to a new promise, then call .then() on the promise with a callback&#10;to execute once the function is done.&lt;/p&gt;</description></item></channel></rss>