Skip to main content

For each Loop

One way to loop over the elements in an array using visual basic is to use For each loop. Because it automatically loops over all elements in the array or collections. And it works well when you can associate each iteration of a loop with a control variable and determine that variable’s initial and final values. And you don’t have to worry about getting the indices in order to get all the elements. For Each Loop Syntax

For Each element [ As datatype ] In group
    [ statements ]
    [ Continue For ]
    [ statements ]
    [ Exit For ]
    [ statements ]
Next [ element ]

Add new comment