VB judgment statements and loop statements and vb judgment statements
Judgment statement • If statement
The if statement can be written in four ways:
First Syntax: If condition judgment statement then program code
Second Syntax: If condition judgment statement then program code else program code
Third Syntax:
If condition judgment statement then
Code
Else
Code
End if
Fourth syntax
If condition judgment statement then
Elseif condition judgment statement then
Code
Elseif condition judgment statement then
Code
......
Else
Code
End if
• Select statement
The syntax of the Select statement is:
Select Case Condition Statement
Case Condition Statement result 1
Code
Case Condition Statement result 2
Code
......
Case else
Code
End Select
Loop statement
• Do statement
There are four types of Do statement Syntax:
In the code of the following four do statements, you can add the exit do statement to exit the loop where appropriate.
The first do statement:
Do While condition judgment statement
Code
Loop
Note: When the condition judgment statement is true, the program code is repeatedly executed until the condition is false.
The second do statement:
Do Until condition judgment statement
Code
Loop
Note: If the condition-based statement is true, repeated program code execution is stopped.
Third do statement:
Do
Code
Loop While condition judgment statement
Note: The program code is executed first, and the condition judgment statement is judged. The running result is the same
The first do while statement.
The fourth do statement:
Do
Code
Loop Until condition judgment statement
Note: first run the code, and then judge the do until statement of the second type.
• For statement
The syntax of the For statement is as follows:
First For statement
For value variable = start value to end value step interval value
Code
Next value variable
Note: In this syntax, the start and end numeric variables are the same variable.
The second For statement
For each element variable in object or array name
Code
Next
• While statement
Syntax:
While condition judgment statement
Code
End While
Note:
This statement and the do statement have the same meaning. The main difference is that the do loop
First, perform a loop unconditionally, and then make a judgment, while the while loop is first
Perform the judgment and then execute the loop. If the initial condition is false, the loop
It won't be done once.