It is necessary to check the three elements (second, third, fourth) of the array for compliance with the ranges at the same time

if array[1] < 1 || array[2] < 1 || array[3] < 1 { print("хотя бы один из элементов меньше 1") } else if array[1] == 1...10 || array[2] == 1...10 || array[3] == 1...10 { // ЭТА ЗАПИСЬ НЕ ПРАВИЛЬНАЯ!!!!!! КАК СОСТАВИТЬ ПРАВИЛЬНО???????? print("элементы от одного до десетяти") } else { print("элементы больше десяти") } 

I can not figure out, through switch, it is possible only to check one element of the array separately, but you need three at a time

The necessary conditions:

1- if at least one of the elements (second, third, fourth) or all three is less than one, then ...

2 — if at least two elements (in the second, third or fourth) are in the range from 1 to 10, and the remaining one is more than ten, or all in the range from 1 to 10, then ...

3 - if at least two elements (secondly, third or fourth) in the range of more than 10, and the remaining one in the range from 1 to 10, or all in the range of more than 10, then ...

  • если то.. and you have если - иначе если - Sublihim

1 answer 1

It is wrong to write in if. Nessesary to use:

 if 1...10 ~= yourNum {} 

If it is not clear how to make a condition, write as much as possible for yourself in order to understand this condition. There are a couple of numbers in the range 1 ... 10, and the third> 10, then there are probably 3 variants:

1 for the range, 2 and 3 in. or

2 beyond the range, 1 and 3 in. or

3 over the range, 2 and 1 in.

Given the first condition, you can simply check for <= 10 and> 10:

1 more than 10, 2 and 3 less. or

2 more 10, 1 and 3 less. or

3 more 10, 2 and 1 less.