Often in programming, one is stuck in some piece of code which does not seem to do what it is supposed to. On such occasions, there are some steps which can be typically useful:

  1. Talk to anyone about the issue. Even if the person is not a programmer, verbalizing the problem helps
  2. Try various things by changing the code and running tests in a trial and error manner
  3. Try a good old google search
  4. Check any reference books online or offline