Skip to main content

ASP.NET Loops and Arrays


In this tutorial I will teach you how to make a loop statement and arrays in ASP.NET.

Included:

For Loops
For Each Loops
While Loops
Arrays

Source Code

For Loops
If you need to run the same statements repeatedly, you can make a program that loop.
If you know how many times you want to loop, you can use a for loop. This kind of loop is especially useful for counting up or counting down.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. @For i=10 To 21
  7. @<p>Line #@i</p>
  8. Next i
  9. </body>
  10. </html>

For Each Loops
If you work with a collection or an array, you often to use a for each loop. A collection is a group of similar objects, and the for each loop lets you carry out a task on each item. The for each loop walks through a collection until it is finished the process.

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <ul>
  5. @For Each r In Request.ServerVariables
  6. @<li>@r</li>
  7. Next r
  8. </ul>
  9. </body>
  10. </html>

Result

And if you want a Full Source Code just Download the file in the download button below. Thanks and I hope you learn it. Enjoy Coding.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.