Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 5 / 68

Repeating (the For statement)

This lesson covers looping in VB.NET with a For statement, with the aim of running the same work efficiently.

For ... To ... Next repeats a block. It is one of the most basic constructs in programming, for when you want the same work done a fixed number of times.

The sample code prints the numbers 1 through 5 with For i As Integer = 1 To 5. Note how the single word Next marks the end of the loop — simple and characteristic of VB.NET.

A common early stumble is whether the loop variable is needed after Next. You can write Next i, but a bare Next works just as well. For statements are also the most common way to walk the contents of an array or a list.

The variable name i comes from "index" and is used by convention across many languages. Knowing that helps when reading code elsewhere.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)