Wap-wml-operators

提供:Dev Guides
移動先:案内検索

WAP-WMLオペレーター

算術演算子

WMLスクリプト言語でサポートされている次の算術演算子があります-

変数Aが10を保持し、変数が20を保持すると仮定します-

Operator Description Example
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiply both operands A* B will give 200
/ Divide numerator by denumerator B/A will give 2
% Modulus Operator and remainder of after an integer division B % A will give 0
++ Increment operator, increases integer value by one A++ will give 11
 —  Decrement operator, decreases integer value by one A-- will give 9

比較演算子

以下は、WMLスクリプト言語でサポートされている比較演算子です-

変数Aが10を保持し、変数が20を保持すると仮定します-

Operator Description Example
== Checks if the value of two operands is equal or not, if yes then condition becomes true. (A == B) is not true.
!= Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. (A != B) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true.
Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A ⇐ B) is true.

論理演算子

以下は、WMLスクリプト言語でサポートされている論理演算子です-

変数Aが10を保持し、変数が20を保持すると仮定します-

Operator Description Example
and Called Logical AND operator. If both the operands are true then condition becomes true. (A and B) is true.
or Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. (A or B) is true.
&& Called Logical AND operator. If both the operands are non zero then condition becomes true. (A && B) is true.
Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. (A
B) is true. ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

割り当て演算子

以下は、WMLスクリプト言語でサポートされている割り当て演算子です-

Operator Description Example
= Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assigne value of A + B into C
+= AND assignment operator, It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C + A
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand C -= A is equivalent to C = C - A
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand C *= A is equivalent to C = C * A
/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand C/= A is equivalent to C = C/A
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand C %= A is equivalent to C = C % A

条件演算子

条件演算子と呼ばれるもう1つの演算子があります。 これは、最初に式の真または偽の値を評価してから、評価の結果に応じて2つの指定されたステートメントのいずれかを実行します。 conditioanl演算子はこの構文を持っています-

Operator Description Example
? : Conditional Expression If Condition is true ? Then value X : Otherwise value Y

演算子のカテゴリ

上記で説明したすべての演算子は、次のカテゴリに分類できます-

  • 単一のオペランドの前にある単項プレフィックス演算子。
  • 2つのオペランドを取り、さまざまな算術および論理演算を実行する2項演算子。
  • 条件演算子(三項演算子)。3つのオペランドを取り、最初の式の評価に応じて2番目または3番目の式を評価します。 *代入演算子。変数に値を割り当てます。

WMLスクリプトオペレーターの優先順位

演算子の優先順位は、式内の用語のグループ化を決定します。 これは、式の評価方法に影響します。 特定の演算子は、他の演算子よりも優先順位が高くなっています。たとえば、乗算演算子は加算演算子よりも優先順位が高い-

たとえば、x = 7 + 3* 2;ここで、演算子*が+よりも前にあるため、xには20ではなく13が割り当てられ、最初に3 * 2で乗算されてから7に加算されます。

ここでは、優先順位が最も高い演算子がテーブルの上部に表示され、最も低い演算子が下部に表示されます。 式内では、上位の先行演算子が最初に評価されます。

Category  Operator  Associativity 
Unary  ! ++ --  Right to left 
Multiplicative   */%  Left to right 
Additive   + -  Left to right 
Relational   < ⇐ > >=  Left to right 
Equality   == !=  Left to right 
Logical AND  &&  Left to right 
Logical OR 
  Left to right  Conditional 
?:  Right to left  Assignment