Не могу вывести ниже изложенное выражение через тернарные операторы. Может кто-то подскажет?
let child = 0
let teenager = 12
let youth = 16
let adult = 25
let mature = 40
let elderly = 55
let aged = 75
let anton = 31
var age: String
if anton > aged {
age = "is aged"
} else {
if anton > elderly {
age = "is elderly"
} else {
if anton > mature {
age = "is mature"
} else {
if anton > adult {
age = "is adult"
} else {
if anton > youth {
age = "is youth"
} else {
if anton > teenager {
age = "is a teenager"
} else {
if anton > child {
age = "is a child"
} else {
age = "was never born"
}
}
}
}
}
}
}
print("Anton \(age)")
Ответ
не знаю зачем вам это
let child = 0
let teenager = 12
let youth = 16
let adult = 25
let mature = 40
let elderly = 55
let aged = 75
let anton = 31
var age: String
age = (anton > aged ? "aged" : (anton > elderly ? "is elderly" : (anton > mature ? "is mature" : (anton > adult ? "is adult" : (anton > youth ? "is youth" : (anton > teenager ? "is a teenager" : (anton > child ? "is a child" : "was never born")))))))
print("Anton \(age)")
Комментариев нет:
Отправить комментарий