In visual basic, the Continue statement is useful to transfer the control immediately to the next iteration of loops such as For, While, Do-While from the specified position by skipping the remaining code.
In the previous section, we learned the Exit statement in vb. The main difference between the Exit statement and Continue
statement is, the Exit statement will completely terminate the loop or statement execution but the Continue
statement will transfer the control immediately to the next iteration of the loop.
Following is the syntax of defining the Continue
statement in the visual basic programming language.
In our applications, we can use Continue
statement whenever we want to skip the code execution from the particular position and send back the control to the next iteration of the loop based on our requirements.
Following is the pictorial representation of Continue
statement process flow in a visual basic programming language.
Now, we will see how to use the Continue statement in For, While, Do-While statements with examples in the visual basic programming language.
In visual basic, by using Continue
keyword, we can skip further code execution and send back the control to the next iteration of For loop statement based on our requirements.
Following is the example of using Continue
statement with For loop in a visual basic programming language.
If you observe the above code, we used Continue
statement to pass the control back to the next iteration of For loop whenever the variable i value equals to 3.
When we execute the above visual basic program, we will get the result as shown below.
Suppose you observe the above result whenever the variable i value equals 3. In that case, it skips the further execution of statements and passes the control back to the next iteration of For loop.
This is how we can use Continue
statement in For loop to skip the further execution of statements and send back the control to further iteration of For loop based on our requirements.
In visual basic, we can stop the execution of further statements from the specified position and send back the control to the further iteration of the While loop immediately.
Following is the example of using Continue
keyword in the While loop to pass the control to the next loop iteration in a visual basic programming language.
If you observe the above example, whenever the variable (i) value become 2, we are skipping the further execution of statements and passing the control back to the further iteration of the While loop using Continue
statement.
When we execute the above visual basic program, we will get the result as shown below.
This is how we can use the Continue
statement with While loop to pass the control back to the further iteration of loop based on our requirements.
Following is the example of using Continue
keyword in the Do-While loop to pass the control to the next loop iteration in the visual basic programming language.
If you observe the above example, whenever the variable (i) value become 2, we are skipping the further execution of statements and passing the control back to the further iteration of a loop using Continue
statement.
When we execute the above visual basic program, we will get the result as shown below.
This is how we can use the Continue
statement with Do-While loop to pass the control back to the further iteration of loop based on our requirements.