title: c++ for loop not working properly
body: <p>This code works only when I uncomment</p>
  <pre><code>//else return &quot;null&quot;; 
  </code></pre>
  <p>on the 9th line, but that is not what I need. I tried replacing that line with</p>
  <pre><code>else continue;
  </code></pre>
  <p>but it won't work either. &quot;currentCommand&quot; is a c-style string.</p>
  <pre><code>std::string Parser::dest(){
  //Determines whether C-command has a dest mnemonic
  bool hasDest = false;
  for (int i=0; i&lt;strlen(currentCommand); i++){
      if (currentCommand[i] == '='){
          hasDest = true;
          break;
      }
      //else return &quot;null&quot;;
  }
  
  if (hasDest == false) return &quot;null&quot;;
  
  std::string destm;
  char temp;
  int index = 0;
  temp = currentCommand[index];
  while (temp !=  '='){
      destm += temp;
      index++;
  }   
  return destm;
  }
  </code></pre>
  <p>I was supposed to get an output when I call this function, and I get it when I uncomment <code>//else return &quot;null&quot;</code> .. but it is not the output I need.  But when I leave that line commented, I get no output, and after a while this error appears:</p>
  <blockquote>
  <p>terminate called after throwing an instance of 'std::bad_alloc'</p>
  <p>what():  std::bad_alloc</p>
  <p>1Aborted (core dumped)</p>
  </blockquote>