title: What is the normal way to debug nested for loop?
body: <p>I am writing code for Leetcode problem 38. Count and Say. It doesn't pass the cases, so I add some <code>cout</code> to debug. Please tell me is there a normal way to debug nested for loop, where should I add the <code>cout</code> expression. I don't want to know how to modify the code to pass the cases.<br />
  Here is my code:</p>
  <pre><code>class Solution {
  public:
      string countAndSay(int n) {
          string cur(&quot;1&quot;);
          while (--n) {
              string tmp = cur;
              string next;
              for (int i = 0; i &lt; tmp.size();) {
                  cout &lt;&lt; &quot;i:&quot; &lt;&lt; i &lt;&lt; endl;
                  int count = 1;
                  for (int j = i + 1; j &lt; tmp.size(); j++) {
                      if (tmp[j] != tmp[0]) {
                          break;
                      }
                      count++;
                  }
                  cout &lt;&lt; &quot;count:&quot; &lt;&lt; count &lt;&lt; endl;
                  next += std::to_string(count) + tmp[0];
                  cout &lt;&lt; &quot;cur:&quot; &lt;&lt; cur &lt;&lt; endl;
                  i += count;
              }
              cur = next;
              cout &lt;&lt; n &lt;&lt; cur &lt;&lt; endl;
          }
          
          return cur;
          
      }
  };
  </code></pre>