Combinações de Condições

É possível aplicar condições para grupos e testar grupos aninhados.

É possível usar operadores lógicos para combinar condições na parte if de uma regra.

A seguinte instrução if contém uma condição:

if the customer category is Gold

Na instrução if a seguir, o operador lógico and vincula duas condições:

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

Precedência de and sobre or

Quando os operadores lógicos and e or vinculam condições na parte if de uma regra, o operador and tem precedência sobre o operador or.

Considere a seguinte instrução if:

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

A instrução será true se uma das seguintes condições for true:

  • O cliente tem mais de 60 anos
  • O cliente tem menos de 21 anos e é estudante

Diversas Condições e Parênteses

É possível usar parênteses para esclarecer a precedência de operadores lógicos.

Na seguinte instrução if, os parênteses agrupam um limite de idade com uma categoria:

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

Também é possível usar parênteses para alterar a interpretação das condições.

Na seguinte instrução if, a condição entre parênteses será atendida se o cliente for um estudante com mais de 60 anos ou menos de 21 anos:

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

Diversas Condições que Usam o mesmo Operador Lógico

É possível agrupar condições e aplicar o mesmo operador lógico a todas as condições no grupo usando entre estas instruções:

  • all of the following conditions are true: Este termo de negócios vincula todas as condições no grupo ao operador lógico and.
  • any of the following conditions is true: Este termo de negócios vincula todas as condições no grupo ao operador lógico or.

Na seguinte regra, a ação é executada apenas quando ambas as condições são 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; 

No seguinte exemplo, a ação será executada se a categoria do cliente for Ouro ou o se cliente estiver esperando há mais de cinco minutos:

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;