Skip to main content
Home  › ... 2sxc Apps

Basic Tutorials

Tutorial Home

Using a foreach - the most common way of looping

  • dog
  • cat
  • mouse

1
2
3
4
5
6
<ul>
@foreach(var pet in pets) {
<li>@pet</li>
}
</ul>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Basic for

  • dog
  • cat
  • mouse

1
2
3
4
5
6
<ul>
@for(var i = 0; i < pets.Length; i++) {
<li>@pets[i]</li>
}
</ul>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Using a for index with two lists (arrays)

  • dog - owned by Daniel
  • cat - owned by John
  • mouse - owned by Markus

1
2
3
4
5
6
<ul>
@for(var i = 0; i < pets.Length; i++) {
<li>@pets[i] - owned by @owners[i]</li>
}
</ul>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX