---
title: "How to use For Loop in MVC Razor view?"  
description: "How to use For Loop in MVC Razor view?"  
author: "Anonymous User"  
published: 2020-02-05  
updated: 2020-02-05  
canonical: https://www.mindstick.com/forum/155784/how-to-use-for-loop-in-mvc-razor-view  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# How to use For Loop in MVC Razor view?

[Please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) how we use for [loop in asp.net](https://www.mindstick.com/forum/156909/how-to-use-foreach-loop-in-asp-dot-net-mvc) MVC with a suitable example.

## Replies

### Reply by Nishi Tiwari

Usually, the loops in **[asp.net MVC razor view](https://www.mindstick.com/forum/155780/explain-different-filters-in-asp-dot-net-mvc)** will work the same as other programming languages. In the razor, we can define loop inside or outside code block and so we can use the same looping concept for assign value, define condition and increment or decrement value.

**The syntax of [for loop](https://www.mindstick.com/forum/12568/android-for-loop-not-working-in-main-thread) in asp.net MVC Razor view engine is given below**

```
@for (int i = 0; i < 5; i++)

{

//Code Block

}
```

T**he example of for loop in MVC razor view is given:-**

```
<h2>For loop</h2>

Output:-<br/>

@for (int i = 0; i < 5; i++)
{

@i<br/>


}

```

## Output

The output of for loop example in asp.net MVC Razor view engine is given below

```
 Output:-
01234
```


---

Original Source: https://www.mindstick.com/forum/155784/how-to-use-for-loop-in-mvc-razor-view

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
