썸네일 대표이미지 입니다.

연산자 – Classic ASP 언어 (4)

Classic ASP에서 사용되는 수치 연산자, 비교 연산자, 그리고 논리 연산자에 대해 알아봅니다. 수치 연산자로는 +, -, *, /, , mod가 있으며, 비교 연산자로는 <, <=, >, >=, =, <>가 있습니다. 논리 연산자로는 And, Or, Xor, Not을 사용하여 조건을 판단합니다.

1. 수치 연산자

연산자 기호내 용
+두 수를 더한다.
두 수의 차를 구한다.
*두 수를 곱한다.
/두 수를 나눈다.
 두 수를 나누어 몫을 구한다.
mod두 수를 나누어 나머지 값을 구한다.
<% Option Explicit %>
     
<%
   Dim int_1, int_2

   int_1 = 10
   int_2 = 4
   
   Response.Write "+ : " & (int_1 + int_2) & "</br>"
   Response.Write "- : " & (int_1 - int_2) & "</br>"
   Response.Write "* : " & (int_1 * int_2) & "</br>"
   Response.Write "/ : " & (int_1 / int_2) & "</br>"
   
   Response.Write " : " & (int_1  int_2) & "</br>"
   Response.Write "mod : " & (int_1 mod int_2) & "</br>"
%>
실행 결과 화면입니다.

2. 비교 연산자

연산자 기호예 시내 용
<a < ba 가 b 보다 작으면 참이다.
<=a <= ba 가 b 보다 작거나 같으면 참이다.
>a > ba 가 b 보다 크면 참이다.
>=a >= ba 가 b 보다 크거나 같으면 참이다.
=a = ba 와 b 가 같으면 참이다.
<>a <> ba 와 b 가 다르면 거짓이다.
<% Option Explicit %>
     
<%
   Dim int_1, int_2
   Dim str_1, str_2

   int_1 = 10
   int_2 = 4
   
   Response.Write "< : " & (int_1 < int_2) & "</br>"
   Response.Write "<= : " & (int_1 <= int_2) & "</br>"
   Response.Write "> : " & (int_1 > int_2) & "</br>"
   Response.Write ">= : " & (int_1 >= int_2) & "</br>"
   Response.Write "= : " & (int_1 = int_2) & "</br>"
   Response.Write "<> : " & (int_1 <> int_2) & "</br>"

   str_1 = "blueshare"
   str_2 = "BLUESHARE"
   
   Response.Write "[1] 문자열(=) : " & (str_1 = str_2) & "</br>"
   Response.Write "[2] 문자열(=) : " & (UCase(str_1) = str_2) & "</br>"
%>
실행 결과 화면입니다.

3. 논리 연산자

연산자 기호내 용
And두 식이 모두 True인 경우만 True 이다.
Or두 식중 하나라도 True인 경우 True 이다.
Xor두 식중 하나는 True 이고 하나는 False 이면 True 이다.
NotTrue 이면 False, False 이면 True 이다.
<% Option Explicit %>
     
<%
   Dim bool_1, bool_2, bool_3

   bool_1 = True
   bool_2 = False
   bool_3 = Not(bool_1)

   Response.Write "AND : " & (bool_1 And bool_2) & "</br>"
   Response.Write "OR : " & (bool_1 Or bool_2) & "</br>"
   Response.Write "XOR : " & (bool_1 Xor bool_2) & "</br>"
   Response.Write "NOT : " & bool_3 & "</br>"
%>
실행 결과 화면입니다.

함께 보면 좋은 게시글

위로 스크롤