If .. then the judgment statement is a one-line hypothetical judgment statement, which will follow the comparison or logical expression given by the user.
Make a judgment. When the judgment result is true, that is, true, the subsequent program code block is executed, otherwise, the execution step of the block is skipped.
The usage of grammar is as follows:
If the statement is judged and then executed
or
If you judge
Execute statement 1
Execute statement 2
If ... it will be over.
In fact, the above two grammars are not the same, the main difference is that the first one is that the source code used in the handler part is shorter.
When segmentation is not required:
If a> then prints "a>b"
When the handler part needs to be segmented, the second writing method must be used to include the execution statement in "If ... and then ... end condition:
If a>b, then
c = a + b
Print "a+b ="&; c
If ... it will be over.
If ... and then ... other ... End If statements can handle situations that do not meet conditional expressions, give them to Else and then connect the program code:
For example:
If a<b, then
c = a + b
other
c = a - b
If ... it will be over.
Print c
In the above program fragment, the value of the variable c will be determined by the conditional expression "a"
As for the syntax of ElseIf, it is also used with If, which is mainly used to make multiple logical judgments.
If ... Ersev ... Other ... End If uses the following syntax:
If the formula 1 is judged, then? //When it is judged that the formula 1 holds, execute the following statement.
Program statement a
What about ElseIf judgment 2? //When the judgment formula 1 is not true, but the judgment formula 2 is true, execute the following statement.
Program statement b
ElseIf judgment 3? //When the judgment formulas 1 and 2 are not programmed, but the judgment formula 3 holds, execute the following statement.
Program statement c
Else // When all the above judgments fail, execute the following statement.
Program statement d?
If ... it will be over.
★ Select case judgment statement
The Select Case flow control statement can execute different program code fragments according to the judged return value.
Select Case syntax is as follows:
Select case parameters
Case conditions 1? //When the judgment formula meets the condition 1, execute the following statement.
Program statement 1
Program statement 2
Situation two? //When the judgment formula meets the condition 2, execute the following statement.
Program statement 1
Program statement 2
Case Else // When it is judged that any conditions are not met, the statement after the case else tag is executed.
Program statement 1
End selection
Because the Select Case can only pass in one parameter, that is, it can't perform "compare" and "judge" operations.
It can only be a number, not an expression.
The following is a fragment of an error program:
Choose case A>b? //Error! ! ! Only one parameter can be passed.
or
Select case a.
Case A<c? //Error! ! ! Case can only accept numeric values.
★ Loop statement
When a program needs to perform repetitive work, it can use loop control statements to continuously execute a program code until certain conditions are met.
Stop.
VB provides three kinds of loop control syntax: Fot ... Next, when ... Wend and Do ... Leo.
For the next loop statement of ...
For ... the next step is to test the loop control statement first, which belongs to the basic loop control syntax. It is based on initial value, final value
And step expressions are used to repeatedly execute a specific program segment. Before each execution, the system will first check whether the current initial state meets the requirements.
Final value condition, if the final value condition is not met, the incremental operation is performed first, and then the loop statement is executed; Otherwise, if it meets the final value condition, then
Jump out of the loop.
The syntax of the For loop is as follows:
For the initial value to the final value step size step size
Program statement
then