条件の組み合わせ

ルールの if 部分で複数の条件を結合します。

論理演算子を使用して、if 部分の条件を結合できます。

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

if the customer category is Gold

次のステートメントでは、論理演算子 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 age of 'the customer' is more than 60 
	or the age of 'the customer' is less than 21 
	and the category of 'the customer' is Student 

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

  • 顧客は 60 歳を超えている
  • 顧客は 21 歳未満であり、かつ顧客は学生である

複数の条件と括弧

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

次のステートメントでは、括弧によって年齢制限とカテゴリーがグループ化されます。

if 
	the age of 'the customer' is more than 60 
	or (the age of 'the customer' is less than 21 and the category of 'the customer' is Student) 

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

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

if 
	(the age of 'the customer' is more than 60 or the age of 'the customer' is less 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 
		- there is at least one member in the members of 'the Gold team'
 then 
	print "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 waiting duration of 'the customer' in minutes is more than 5  
then 
	print "redirect the call to a member of the Gold team";