ASP.NET RazorVB logical conditions can execute code based on corresponding conditions.
Programming logic: Execute code based on conditions.
VB allows conditional execution of code.
Use if statements to determine conditions. Depending on the judgment result, the if statement returns true or false:
if statement starts a block of code
The condition is written between if and then
If the condition is true, the code between if ... then and end if is executed
@CodeDim price=50End Code
<html> <body> @If price>30 Then@<p>The price is too high.</p>End If</body> </html>
The if statement can contain else conditions .
The else condition defines the code to be executed when the condition is false.
@CodeDim price=20End Code<html> <body> @if price>30 then@<p>The price is too high.</p>Else@<p>The price is OK.</p>End If</ body> </htmlV>
Note: In the above example, if the first condition is true, the code in the if block will be executed. The else condition covers "everything else" except the if condition.
Multiple conditional judgments can use elseif conditions :
@CodeDim price=25End Code<html> <body> @If price>=30 Then@<p>The price is high.</p>ElseIf price>20 And price<30 @<p>The price is OK.< /p>Else@<p>The price is low.</p>End If</body> </html>
In the above example, if the first condition is true, the code in the if block will be executed.
If the first condition is not true and the second condition is true, the code in the elseif block will be executed.
There is no limit to the number of elseif conditions.
If neither the if nor elseif conditions are true, the final else block (without the condition) covers "everything else".
The select block can be used to test some individual conditions:
@CodeDim weekday=DateTime.Now.DayOfWeekDim day=weekday.ToString()Dim message=""End Code<html> <body> @Select Case dayCase "Monday" message="This is the first weekday."Case "Thursday" message="Only one day before weekend."Case "Friday"message="Tomorrow is weekend!"Case Elsemessage="Today is " & dayEnd Select<p> @message</p> </body> </html>
"Select Case" is followed by the test value (day). Each individual test condition has a case value and any number of lines of code. If the test value matches the case value, the corresponding line of code is executed.
The select block has a default case (Case Else), which overrides "all other cases" when none of the specified cases match.
The above is an introduction to the use of ASP.NET RazorVB logical conditions.