<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Programming]]></title><description><![CDATA[How to design and develop a solution program]]></description><link>https://forum.creaticode.com/category/8</link><generator>RSS for Node</generator><lastBuildDate>Mon, 11 May 2026 18:35:20 GMT</lastBuildDate><atom:link href="https://forum.creaticode.com/category/8.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 Jul 2022 20:15:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Nested Loops]]></title><description><![CDATA[<p dir="auto"> </p>
<h2><a class="anchor-offset" name="prerequisite"></a>Prerequisite</h2>
<ul>
<li><a href="/topic/83/the-for-loop-block">The For-Loop Block</a></li>
<li><a href="/topic/85/the-repeat-block">The Repeat Block</a></li>
<li><a href="/topic/278/the-repeat-until-block">The Repeat Until Block</a></li>
<li><a href="/topic/125/the-forever-block">The Forever Block</a></li>
</ul>
<p dir="auto"> </p>
<h2><a class="anchor-offset" name="what-are-loops"></a>What are Loops?</h2>
<p dir="auto">A “loop” is a block for playing other blocks repeatedly. Below are some loop blocks you can use on the CreatiCode playground;</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/99b9f4b3-7f59-468b-951e-85a8cf56df23.PNG" width="600" /><br />
 </p>
<h2><a class="anchor-offset" name="what-are-nested-loops"></a>What are Nested Loops?</h2>
<p dir="auto">When you put one loop inside another loop, it becomes a “nested loop”. You can even have a third loop inside the inner loop.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/172caa68-5066-4284-bee5-741a6074bd29.PNG" width="650" /><br />
 </p>
<h2><a class="anchor-offset" name="how-nested-loops-work"></a>How Nested Loops Work?</h2>
<p dir="auto">When you run a program with a nested loop, the inner (child) loop will work like a normal loop. However, because of the outer (parent) loop, the inner loop itself will be repeated.</p>
<p dir="auto">Here is a step-by-step example:</p>
<p dir="auto"><strong>Step 1:</strong> The main loop is played.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/40dc7f7b-c0ef-4d55-bbad-441fffd90d8f.PNG" width="250" /><br />
 </p>
<p dir="auto"><strong>Step 2:</strong> The Nested loop is started.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/8e019f92-f199-47db-83f5-c3c1ba471d9f.PNG" width="250" /><br />
 </p>
<p dir="auto"><strong>Step 3:</strong> The blocks inside the nested loop are played until the condition of the nested loop is completed.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/fa777e85-4b6f-45a4-a44e-ba5f403d904e.PNG" width="600" /><br />
 </p>
<p dir="auto"><strong>Step 4:</strong> The blocks after the nested loop are played (if there are any).</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c84877e2-eda9-46bd-8460-2c36ba9dc34b.PNG" width="300" /><br />
 </p>
<p dir="auto"><strong>Step 5:</strong> The main loop is restarted.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/aae95727-c95e-4245-bd9d-826b67fca119.PNG" width="300" /></p>
<p dir="auto"><strong>Note: All of the above 5 steps keep repeating until the condition of the main loop is completed.</strong></p>
<p dir="auto">For example, as shown below, <strong>“repeat until ” is the nested loop,</strong> which keeps the monkey moving until it touches the edge of the stage. And <strong>“repeat (5)” is the main loop</strong> which repeats the nested loop 5 times.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/fe3888f6-abfc-4a68-9af2-801a9e66a68b.gif" width="800" style="border-radius:5px;border:1px solid #29622d" /><br />
 </p>
<h2><a class="anchor-offset" name="use-of-nested-loops"></a>Use of Nested Loops</h2>
<p dir="auto">We use Nested loops when we want to repeat multiple blocks at the same time, until multiple conditions are completed.</p>
<p dir="auto">For example, as shown below, nested loops are used to make the monkey move and eat bananas at the same time.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/44c7889a-6f2e-4a55-8144-6bd2a58a110a.gif" width="800" style="border-radius:5px;border:1px solid #29622d" /><br />
 </p>
]]></description><link>https://forum.creaticode.com/topic/345/nested-loops</link><guid isPermaLink="true">https://forum.creaticode.com/topic/345/nested-loops</guid><dc:creator><![CDATA[info-creaticode]]></dc:creator><pubDate>Sat, 23 Jul 2022 20:15:51 GMT</pubDate></item></channel></rss>