T4 Toolbox - mixing class feature and statement blocks
While @GarethJ's answer explains why this happens, it does not tell you how to fix it. You need to add a plus sign, i.e. use <#+
instead of just <#
<#+ for (int i = 0; i < 10; i++) { #>
<#= i #>
<#+ } #>
After the first class feature block, you need to make all the subsequent statement blocks also class feature blocks.
Under the covers, the first class feature block terminates the behind the scenes "Generate" method and switches to inserting the content as members of the template's behind the scenes class.
If you're using Visual Studio 2010, you can always create a preprocessed template and paste your regular template code into that to see what's going on under the hood.
You should have all class features in the same feature block, below any output.