For - ForEach
For
for (int icount = 2; icount <= 20; ivalue++)
{
break; //terminates the closest ending loop or switch
}
For icount = 1 to 20 'the variable is automatically declared
Next icount
For icount As Integer = 1 to 20 'the variable is declared on the same line
Next icount
Dim icount As Integer 'the variable is declared earlier
For icount = 1 to 20
Next icount
ForEach
If you are iterating through anything that is not a collection you should always use a for loop. It is a lot more efficient than a foreach loop.
foreach (System.Windows.Forms.DataGridViewRow objRow in objDataGridView.Rows)
{
}
Dim objRow As System.Windows.Forms.DataGridViewRow
For Each objRow In objDataGridView.Rows
Next objRow
ForEach (reverse)
for (icount = 20; icount > -1; ivalue--)
{
}
For icount As Integer = 20 to 1 Step -1
Next icount
Continue
The continue statement transfers execution to the next iteration within the loop
for (int icount = 2; icount <=10; icount++)
{
if (icount = 6) {
continue;
}
}
For icount As Integer = 2 To 10
If (icount = 6) Then
Continue For
End If
Next
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext