【英文】VB的循环语句

Preface

Notes on learning VB loop statements

For Loop statement

  • Repeat executing the code that meets the conditions in the range of [starting value, ending value]
1
2
3
For i = starting value To ending value Step increment
Code to be repeatedly executed when the condition is met
Next i
  • The increment can usually be omitted, and the default increment is 1
1
2
3
For i = starting value To ending value
Code to be repeatedly executed when the condition is met
Next i
  • The variable name can be omitted to exit the loop
1
2
3
For i = starting value To ending value
Code to be repeatedly executed when the condition is met
Next

Exit the loop immediately

1
Exit For

Do While Loop statement

1
2
3
Do While condition
Code to be repeatedly executed when the condition is met
Loop

Exit the loop immediately

1
Exit Do

Do Until Loop statement

  • The Do Until Loop statement is opposite to the Do While Loop statement in terms of the conditions
1
2
3
Do Until condition
Code to be repeatedly executed when the condition is not met
Loop

Exit the loop immediately

1
Exit Do

Do…While Loop statement

  • The difference between the Do…While Loop statement and the Do While Loop statement is that Do…While executes the code once and then performs the judgment, while Do While performs the judgment first and then executes the code
1
2
3
Do
Code to be repeatedly executed when the condition is met
Loop While condition

Exit the loop immediately

1
Exit Do

Do…Until Loop statement

  • The difference between the Do…Until Loop statement and the Do Until Loop statement is that Do…Until executes the code once and then performs the judgment, while Do Until performs the judgment first and then executes the code
1
2
3
Do
Code to be repeatedly executed when the condition is not met
Loop Until condition

Exit the loop immediately

1
Exit Do

Done

References

Bilibili - Jiao Da You