+ 1

Swift problem

Well, how do you use "&&" and "!=" on the same line in swift? I was solving a code coach problem when I encountered that problem. In the attached code is a snippet of what the problem is. That code is valid in other languages. Like if I want to check for a number that is a multiple of 2 but not 4, I should be able to do it as Let a = 6 if (a%2==0 && a%4!=0) //do something This code doesn't work in swift. It throws an error about && and != appearing on the same line or something along that line. https://code.sololearn.com/cev43yWWMnIF/?ref=app

20th Jan 2021, 8:02 PM
Sekiro - avatar
2 Answers
+ 2
it should work, but you didn't put any spaces between operators and values. (a > 3 && a != 8) not (a>3 && a!=8)
20th Jan 2021, 10:40 PM
Bahha🐧 - avatar
+ 3
Bahha🐧 Thanks man. That worked. Swift is really strict with spaces😣😣
20th Jan 2021, 11:21 PM
Sekiro - avatar