I am a newbie when it comes to programming and just started learning Swift. Your help would be appreciated for the below array concept I am trying to work out.
How can I make the below coding shorter so that I can reduce the amount of If Statements. So when a "battlename = name[0]" index is selected the statement automatically selects the corresponding monsters at the same index level without having to use so many If statements.
Hope I'm making sense.
var names = ["Lancelot", "Arthur", "Gawain", "Galahad"]
var monsters = ["Dragon", "Boar", "Giant", "Griffin"]
let battlename = names[1]
print(battlename, "Vs.", monsters)
if battlename == names[0] {
print(battlename, "Vs.", monsters[0])
}
else if battlename == names[1] {
print(battlename, "Vs.", monsters[1])
}
else if battlename == names[2] {
print(battlename, "Vs.", monsters[2])
}
else if battlename == names[3] {
print(battlename, "Vs.", monsters[3])
}