ASP.NET RazorLesson 22Free preview
Razor C# Loops
This lesson is part of ASP · All levels
Summary
Razor supports C# repetitions such as foreach, for, and while to repeat the appearance of data from a particular collection or count. Loops are written in the @{} block or directly followed by the HTML block so that each iteration produces a new page element. Repetitions are very useful for product lists, table rows, or dynamic navigation menus.
Key points
- Foreach is used to repeat all the elements of a collection without managing the index.
- For is used when the number of iterations or iteration steps is known.
- While checking the condition before each iteration.
- Break stops the repetition, while continue continues to the next iteration.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.