Generally, the loops in asp.net mvc razor view will work same as other programming languages. We can define loop inside or outside code block in the razor and use the same looping concept for assign value, define condition and increment, or decrement value.
The following represents the syntax of for loop in asp.net mvc razor view engine.
@for (int i = 0; i < 5; i++)
{
//Code Block
}
The following is the example of for loop in the mvc razor view.
<h2>For loop</h2>
Output:-<br/>
@for (int i = 0; i < 5; i++)
{
@i<br/>
}
The following is the output of for loop example in asp.net mvc razor view engine.