Hi. I'm getting the «Expected expression» for some reason but don't understand why.
let index = 3
if index <= devices.count {
print(devices[index])
else {
return "the array is out of range"
}
}
Any answer appreciated.
Hi. I'm getting the «Expected expression» for some reason but don't understand why.
let index = 3
if index <= devices.count {
print(devices[index])
else {
return "the array is out of range"
}
}
Any answer appreciated.
You missed the closing curly bracket before end
.
if index <= devices.count {
print(devices[index])
} // <<-- THIS missing
You should use
if ... {
} else {
}
not
if ... {
else {
}
}
Because the test is wrong.
it should be
if index < devices.count && index >= 0 {
Okay ! Thanks @Claude31.