+ 1

Why is it not working?

var distance=4 if distance==0{ print("not a valid distance") } else if distance==1 || distance==2 || distance==3 || distance==4 || distance ==5{ print("near")} else{ print("too far")}

13th Aug 2020, 5:25 AM
Baratov Hojiakbar
Baratov Hojiakbar - avatar
4 Respuestas
+ 5
EDIT: I wasn't aware that space matters in swift, their should be space around the operators like in your if case if distance==0 is considered wrong it should be distance == 0, (have space around the operators https://code.sololearn.com/cq8GKB2dN2j6/?ref=app
13th Aug 2020, 5:36 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 7
Give some spaces between == equality operator after distance and before right value it will work without any errors
14th Aug 2020, 6:23 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Мг. Кнап🌠 No i didn't copy it. I tried to write the switch ,case and default with boolean and if statements.
13th Aug 2020, 5:48 AM
Baratov Hojiakbar
Baratov Hojiakbar - avatar
+ 1
Baratov Hojiakbar i take my words back, see the edited response, hope it answers your question
13th Aug 2020, 5:49 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar