条件の組み合わせ

グループに条件を適用し、ネストされたグループをテストすることができます。

論理演算子を使用して、ルールの if 部分に含まれる複数の条件を組み合わせることができます。

次の if ステートメントには、1 つの条件が含まれています。

if the customer category is Gold

以下の if ステートメントでは、論理演算子 and が 2 つの条件をリンクします。

if the category of the customer is Gold and the customer has been waiting longer than 5 minutes 

and は or に優先する

論理演算子の and と or で、ルール内の if 部分の条件がリンクされている場合、and 演算子が or 演算子に優先します。

次の if ステートメントがあるとします。

if 
	the customer is older than 60 
	or the customer is younger than 21 
	and the category of the customer is Student 

以下の条件のいずれかが true の場合に、このステートメントは true になります。

  • 顧客は 60 歳を超えている
  • 顧客は 21 歳未満であるおよび顧客は学生と同一である

複数の条件と括弧

括弧を使用して、論理演算子の先行を明確にすることができます。

次の if ステートメントでは、年齢制限とカテゴリーを括弧によりグループ化しています。

if 
	the customer is older than 60 
	or (the customer is younger than 21 and the category of the customer is Student) 

また、括弧を使用して、条件の解釈を変更することもできます。

以下の if ステートメントでは、顧客が 60 歳を超えているか 21 歳未満である学生の場合に、括弧内の条件が満たされます。

if 
	(the customer is older than 60 or the customer is younger than 21) 
	and the category of the customer is Student

同じ論理演算子を使用する複数の条件

以下のステートメントを使用して、条件をグループ化し、そのグループ内のすべての条件に同じ論理演算子を適用できます。

  • all of the following conditions are true: このビジネス用語は、論理演算子 and を使用して、グループ内のすべての条件をリンクします。
  • any of the following conditions is true: このビジネス用語は、論理演算子 or を使用して、グループ内のすべての条件をリンクします。

以下のルールでは、両方の条件が true の場合にのみ、アクションが実行されます。

if 
	all of the following conditions are true: 
		- the category of the customer is Gold 
		- a member of the Gold team is available 
then 
	redirect the call to a member of the Gold team; 

次の例では、顧客のカテゴリーがゴールドであるか、顧客の待ち時間が 5 分を超えた場合に、アクションが実行されます。

if 
	any of the following conditions is true: 
		- the category of the customer is Gold 
		- the customer has been waiting longer than 5 minutes 
then 
	redirect the call to a member of the Gold team;