Академический Документы
Профессиональный Документы
Культура Документы
Elementos
Término Definición
Ejemplo
En el ejemplo siguiente, las instrucciones del bucle continúan ejecutándose hasta que la
variable index es superior a 10.
VB
Dim index As Integer = 0
While index <= 10
Debug.Write(index.ToString & " ")
index += 1
End While
Debug.WriteLine("")
' Output: 0 1 2 3 4 5 6 7 8 9 10
En el siguiente ejemplo se muestra el uso de las instrucciones Continue While y Exit While.
VB
Dim index As Integer = 0
While index < 100000
index += 1
Debug.WriteLine("")
' Output: 1 2 3 4 9 10
En el ejemplo siguiente se leen todas las líneas de un archivo de texto. El método OpenText abre el
archivo y devuelve un StreamReader que lee los caracteres. En la condición de While , el método
de Peek de StreamReader determina si contiene caracteres adicionales.
For
Parts
Part Description
counter Required in the For statement. Numeric variable. The control variable for the loop. For more
information, see Counter Argument later in this topic.
datatype Optional. Data type of counter . For more information, see Counter Argument later in this topic.
step Optional. Numeric expression. The amount by which counter is incremented each time through
the loop.
statements Optional. One or more statements between For and Next that run the specified number of times.
In the following example, the index variable starts with a value of 1 and is
incremented with each iteration of the loop, ending after the value
of index reaches 5.
VBCopy
In the following example, the number variable starts at 2 and is reduced by 0.25 on
each iteration of the loop, ending after the value of number reaches 0.
The Step argument of -.25 reduces the value by 0.25 on each iteration of the
loop.
VBCopy