title: How can a razor for loop be used in a javascript script tag?
body: <p>The error generated is "Conditional Compilation is turned off".</p>
  
  <p>Conditional Compilation hack from MSDN is prevalent but fails.</p>
  
  <p>There are several questions like this one:
  <a href="https://stackoverflow.com/q/6655696/1026459">Conditional Compilation is turned off in Razor?</a></p>
  
  <p>They all point to the answer of:</p>
  
  <pre><code>/*@cc_on @*/
  </code></pre>
  
  <p>From the article seen here at the MSDN:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/5y5529x3(v=vs.90).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/5y5529x3(v=vs.90).aspx</a></p>
  
  <p>However, this hack is pretty fail or I seem to fail at implementing it. The trailing <code>@*</code> causes the remaining code in the .cshtml file to become commented out. Moreover, <code>@cc_on</code> gives an error "cc_on does not exist in the current context".</p>
  
  <p>Here is a piece of code to test in a .cshtml file:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   @for(int i = 0; i &lt; 5; i++)
   {
      document.write(@i);
   }
  &lt;/script&gt;
  </code></pre>
  
  <p>Which will cause the "Conditional Compilation is turned off" message. Attempting to insert the workaround in there will cause various other messages such as "cc_on" does not exist in the context", "expected ,", or "expected ;", or "expected )" from the for loop. </p>
  
  <p>How can a razor for loop be used in a javascript script tag?</p>