ASP dùng 4 câu lệnh điều kiện như sau:
a) Dạng 1: If <điều kiện> Then <câu lệnh> End If (Nếu điều kiện đúng thì thực hiện câu lệnh sau Then
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="vi" />
<body>
<%
Dim a
a=10
If a>0 Then
response.write("Số dương")
End If
%>
</body>
</html>
b) Dạng 2: If <điều kiện> Then <câu lệnh 1> Else <câu lệnh 2> End If (Nếu điều kiện đúng thì thực hiện câu lệnh 1, nếu điều kiện sai thì thực hiện câu lệnh 2)
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="vi" />
<body>
<%
i=hour(time)
If i < 12 Then
response.write("Chào buổi sáng!")
Else
response.write("Chào buổi chiều")
End If
%>
</body>
</html>
c) Dạng 3: If <điều kiện> Then <câu lệnh> Else If <điều kiện> ... (nhiều câu lệnh if lồng nhau)
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="vi" />
<body>
<%
i=22 'hour(time)
If i < 10 Then
response.write("Chào buổi sáng")
ElseIf i <13 Then
response.write("Chào buổi trưa")
ElseIf i < 17 Then
response.write("Chào buổi chiều")
ElseIf i < 21 Then
response.write("Chào buổi tối")
Else
response.write("Chúc ngủ ngon")
End If
%>
</body>
</html>
d) Dạng 4: Select Case <biến đếm> Case <giá trị 1> <câu lệnh 1> .... Case Else <câu lệnh n> End Select
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="vi" />
<body>
<%
d=weekday(date)
Select Case d
Case 1
response.write("Sleepy Sunday")
Case 2
response.write("Monday again!")
Case 3
response.write("Just Tuesday!")
Case 4
response.write("Wednesday!")
Case 5
response.write("Thursday...")
Case 6
response.write("Finally Friday!")
Case else
response.write("Super Saturday!!!!")
End Select
%>
</body>
</html>
https://tritue.edu.vn/tuecode/tracnghiem30/index.php/baiviet/post/view/id/192?id=192