VB lets you execute code based on conditions.
To test a condition you use the if statement. The if statement returns true or false, based on your test:
- The if statement starts a code block
- The condition is written between if and then
- The code between if ... then and end if is executed if the test is true
Example
@Code
Dim price=50
End Code
<html>
<body>
@If price>30 Then
@<p>The price is too high.</p>
End If
</body>
</html>
Dim price=50
End Code
<html>
<body>
@If price>30 Then
@<p>The price is too high.</p>
End If
</body>
</html>
Practice Excercise Practice now