Razor if statement counter issue v7.4

Hi,

I’m new to Razor and trying to carry out what should be a simple task but my code is not working.
I am displaying the results of a query (in a partial) and within that query I have set up a counter so that I can wrap different HTML around the items, depending which number they are.

So, it looks like this:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage


@{ var selection = CurrentPage.Site().FirstChild("articleRepo").Children("article").Where("Visible").OrderBy("CreateDate desc").Take(10); }

@if (selection.Any())
{
    var n = 0;
    <div>

        @foreach (var item in selection)
        {
            var imagePath = @item.image640;
            n++;

            if(n==1){
            do one things
            } else {
            do another
            }

            <div class="col-sm-6 hp-two-story">
                @n<img class="lazy" data-original="@("http://www.website.org" + imagePath)" />
                <p><a href="@item.Url">@item.Name</a></p>
            </div>
        }
    </div>
}

The content shows just fine until I put the..

      if(n==1){
        do one things
        } else {
        do another
       }

Then it throws errors. I msut have tried 100 variations of this, but I’m close to going insane. I get the same errors whether using Back OFfice or VS.


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/75791-razor-if-statement-counter-issue-v74