ASP.NET 면도기 VB 로직
로직 프로그래밍 : 조건부 코드를 실행합니다.
조건 경우
VB는 조건 코드 실행이 허용.
조건을 결정하는 경우 문을 사용합니다. 판정 결과에 따라, 문 true 또는 false를 반환하는 경우 :
- 문은 코드 블록을 시작하면
- 다음의 경우 사이에 작성된 약관
- 코드는 조건은 다음 ... 경우에 해당하며 최종면 사이에 행하면
예
@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>
»인스턴스를 실행
다른 조건
문은 조건을 포함 할 수 있습니다 경우 다른.
조건을 실행하기 위해 거짓이면 다른 조건은 코드를 정의했다.
예
@Code
Dim price=20
End 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>
Dim price=20
End 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>
»인스턴스를 실행
참고 : 위의 예에서, 코드 블록이 실행되는 경우 제 조건이 참일 경우. 다른 조건의 조건에 추가하여 해당되는 경우 "다른 모든 경우."
의 ElseIf 조건
당신은 ELSEIF 조건을 판단하는 여러 기준을 사용할 수 있습니다 :
예
@Code
Dim price=25
End 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>
Dim price=25
End 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>
»인스턴스를 실행
첫 번째 조건에 해당하는 경우 위의 예에서, 코드 블록이 실행됩니다.
첫 번째 조건에 해당되지 않고, 두 번째 조건이 참이면, 코드 ELSEIF 블록이 실행된다.
ELSEIF 조건의 무제한.
는 IF와 ELSEIF 조건에 해당하지 않은 경우 (조건없이) 마지막으로 다른 블록은 "다른 모든 경우를."포함
선택 조건
선택 블록은 분리 조건의 수를 테스트하는데 사용될 수있다 :
예
@Code
Dim weekday=DateTime.Now.DayOfWeek
Dim day=weekday.ToString()
Dim message=""
End Code
<html>
<body>
@Select Case day
Case "Monday"
message="This is the first weekday."
Case "Thursday"
message="Only one day before weekend."
Case "Friday"
message="Tomorrow is weekend!"
Case Else
message="Today is " & day
End Select
<p> @message </p>
</body>
</html>
Dim weekday=DateTime.Now.DayOfWeek
Dim day=weekday.ToString()
Dim message=""
End Code
<html>
<body>
@Select Case day
Case "Monday"
message="This is the first weekday."
Case "Thursday"
message="Only one day before weekend."
Case "Friday"
message="Tomorrow is weekend!"
Case Else
message="Today is " & day
End Select
<p> @message </p>
</body>
</html>
»인스턴스를 실행
"선택 사례"뒤에 시험 (일)의 값 하였다. 각각의 경우 값 시험 조건과 코드 라인의 수 있습니다. 테스트 값이 경우의 값과 일치하는 경우 코드의 대응하는 라인이 실행된다.
선택 블록은 기본 (그렇지 케이스), 지정된 모든 상황이 일치하지 않는 경우, 커버 갖는다 "다른 모든 케이스."