<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cognifyx</title>
    <description>The latest articles on DEV Community by Cognifyx (@cognifyx).</description>
    <link>https://dev.to/cognifyx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4262903%2Ff72fa155-e32c-4808-af3c-43577c40efb8.jpg</url>
      <title>DEV Community: Cognifyx</title>
      <link>https://dev.to/cognifyx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cognifyx"/>
    <language>en</language>
    <item>
      <title>HSC ICT: How to Find the Output of a C Loop — Without Memorizing It</title>
      <dc:creator>Cognifyx</dc:creator>
      <pubDate>Tue, 24 Nov 2026 17:08:15 +0000</pubDate>
      <link>https://dev.to/cognifyx/hsc-ict-how-to-find-the-output-of-a-c-loop-without-memorizing-it-djd</link>
      <guid>https://dev.to/cognifyx/hsc-ict-how-to-find-the-output-of-a-c-loop-without-memorizing-it-djd</guid>
      <description>&lt;p&gt;HSC ICT students in Bangladesh face the same problem every year: a C loop in the question paper, and they have to find the output — without a computer in front of them. Most students try to memorize outputs. That fails the moment the loop changes a little. Here is a better way: trace it, step by step.&lt;/p&gt;

&lt;p&gt;The example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What does this print? The answer is 55 — the sum of 1 to 10.&lt;/p&gt;

&lt;p&gt;Trace it, don't memorize it: i starts at 1, sum is 0. i=1: sum=1. i=2: sum=3. i=3: sum=6. i=4: sum=10... until i=10: sum=45+10=55. i becomes 11, condition i&amp;lt;=10 is false, loop stops. Two questions always answer a loop question: how many times does the loop run (here 10 times) and where does the result accumulate (here, in sum).&lt;/p&gt;

&lt;p&gt;Common mistakes: 1) Forgetting the last value — i&amp;lt;=10 includes 10. 2) Confusing sum+=i with sum=i — sum+=i adds to the running total, sum=i would just overwrite it and the answer would be 10. 3) Starting sum at the wrong value — if sum is not set to 0 first, the result is garbage.&lt;/p&gt;

&lt;p&gt;Running it beats memorizing it: when you run it, you see the output instantly — and when you change i&amp;lt;=10 to i&amp;lt;=5, you see the answer change to 15. That is how the pattern sticks.&lt;/p&gt;

&lt;p&gt;That is what ICT Lab is built for: live HTML, C and SQL labs in the browser, a number-system converter, a logic-gate simulator, chapter quizzes and mock tests, and an AI tutor you can ask in Bangla, English or Banglish. Try the C lab free: &lt;a href="https://ictlab.cognifyx.net/" rel="noopener noreferrer"&gt;https://ictlab.cognifyx.net/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Disclosure: ICT Lab is Cognifyx's own product.&lt;/p&gt;

</description>
      <category>hsc</category>
      <category>c</category>
      <category>programming</category>
      <category>bangladesh</category>
    </item>
  </channel>
</rss>
