<?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: Varadraj Jadhav</title>
    <description>The latest articles on DEV Community by Varadraj Jadhav (@varadraj028).</description>
    <link>https://dev.to/varadraj028</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F99mvlsfu5tfj9m7ku25d.png</url>
      <title>DEV Community: Varadraj Jadhav</title>
      <link>https://dev.to/varadraj028</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/varadraj028"/>
    <language>en</language>
    <item>
      <title>I Stopped Guessing and Started Tracing My Java Loops</title>
      <dc:creator>Varadraj Jadhav</dc:creator>
      <pubDate>Wed, 21 Oct 2026 09:50:06 +0000</pubDate>
      <link>https://dev.to/varadraj028/i-stopped-guessing-and-started-tracing-my-java-loops-3f08</link>
      <guid>https://dev.to/varadraj028/i-stopped-guessing-and-started-tracing-my-java-loops-3f08</guid>
      <description>&lt;p&gt;As a third-year Computer Engineering student, I'm currently learning Java and practicing programming problems to improve my problem-solving skills.&lt;/p&gt;

&lt;p&gt;While learning loops, I realized something important: reading code and understanding how it executes are two different things.&lt;/p&gt;

&lt;p&gt;Sometimes, I could understand what each line was doing, but I still needed to think more carefully about how variable values changed during each iteration.&lt;/p&gt;

&lt;p&gt;That's when I started paying more attention to &lt;strong&gt;tracing variables instead of just guessing the output.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A small Java example
&lt;/h2&gt;

&lt;p&gt;Consider this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;472&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;digit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;digit&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, the code might look straightforward. But let's understand what actually happens when the loop executes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;number % 10&lt;/code&gt; extracts the last digit.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;number / 10&lt;/code&gt; removes the last digit because integer division discards the decimal part.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;while&lt;/code&gt; loop continues as long as &lt;code&gt;number &amp;gt; 0&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of trying to follow everything mentally, let's trace the values step by step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tracing the loop step by step
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Iteration&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;number&lt;/code&gt; before&lt;/th&gt;
&lt;th&gt;&lt;code&gt;digit&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;number&lt;/code&gt; after&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;472&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;47&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;47&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2
7
4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how &lt;code&gt;number&lt;/code&gt; changes after every iteration.&lt;/p&gt;

&lt;p&gt;Initially, it is &lt;code&gt;472&lt;/code&gt;. After the first iteration, it becomes &lt;code&gt;47&lt;/code&gt;, then &lt;code&gt;4&lt;/code&gt;, and finally &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When &lt;code&gt;number&lt;/code&gt; becomes &lt;code&gt;0&lt;/code&gt;, the condition &lt;code&gt;number &amp;gt; 0&lt;/code&gt; is false, so the loop terminates.&lt;/p&gt;

&lt;p&gt;The important part isn't just knowing the output. It's understanding &lt;strong&gt;why those values appear and why the loop eventually stops.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Three questions I ask when tracing a loop
&lt;/h2&gt;

&lt;p&gt;When practicing loop-based programming problems, I'm trying to build the habit of asking myself these three questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What is the current value?&lt;/strong&gt; Identify the values of the important variables before each iteration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What changes during this iteration?&lt;/strong&gt; Follow the statements that update the variables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When will the loop stop?&lt;/strong&gt; Check the loop condition after the values have changed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Writing down a few iterations can make the execution flow much easier to understand, especially when a problem involves multiple variables or several operations inside a loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'm learning from this
&lt;/h2&gt;

&lt;p&gt;I'm still learning Java, and I know that improving problem-solving skills takes practice. But I'm beginning to understand that getting the correct output is only one part of solving a programming problem.&lt;/p&gt;

&lt;p&gt;I also want to be able to explain how the program reaches that output.&lt;/p&gt;

&lt;p&gt;For me, tracing variables is a small but useful step toward writing code with better understanding rather than relying on guesses.&lt;/p&gt;

&lt;p&gt;I'll keep practicing this approach as I work through more Java problems and gradually take on more challenging ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Over to the community :
&lt;/h2&gt;

&lt;p&gt;For developers who have been programming for a while, &lt;strong&gt;what technique helped you understand loops and variable changes when you were starting out?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to learn from your experiences and suggestions!!!!&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>learning</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
