Razor – Loop Statements with Programming Example

In this chapter you will learn

  • How to use looping statements inside razor syntax.
  • Programming example

You can use looping statements as for loop, while loop, do while loop or foreach loop inside razor syntax as follow:

For Loop

Output


Prints 5 times
Prints 5 times
Prints 5 times
Prints 5 times
Prints 5 times
  • While Loop

    Output


    This while loop print 5 times
    This while loop print 5 times
    This while loop print 5 times
    This while loop print 5 times
    This while loop print 5 times

    Foreach loop

    Output

    1, 3, 5, 7, 11, 13, 17, 19,

    Summary

    In this chapter you learned to use looping statements like for loop, while loop, foreach loop in razor syntax. In the next chapter you will learn array with razor.


    Leave a Reply

    Your email address will not be published. Required fields are marked *