title: Javascript switch with global variable
body: <p>I'm trying to use a global variable with a switch statement but the value of the variable is not changing. Perhaps a scope problem?</p>
  
  <p>I need a switch statement to cycle through each case one by one, but the "i" variable keeps resetting to 1 every time I view it in the console.</p>
  
  <p>Why is this happening?</p>
  
  <p><strong>THE CODE</strong></p>
  
  <pre><code>var i = 0;
  
  switch(i){
      case 0:
          i+=1;
          console.log(i);
          break;
      case 1:
          i+=1;
          console.log(i);
          break;
  }
  </code></pre>
  
  <p>and so on...</p>
  
  <p><em>edit:</em> Great support from everybody below, thank you very much.</p>