We all know that in Java, we use the && operator for "and" and || operator or "or". But when it comes to Kotlin, this doesn't work. When I was trying out a simple program, I noticed that the && operator in Kotlin was behaving like the || operator in Java using IntelliJ, I have no idea why.
while(day!=1 && month != 1 && year!= 0) {
...
...
}
When I debugged the program, I saw that when day = 1, month = 8, year = 1947, it jumped out of the loop.
I modified the code and debugged again, this time it jumped out when day = 31, month = 1, year = 1947.
So what exactly is the "and" and "or" operator in Kotlin?
Best Solution
To not jump out of the loop for day = 1, month = 8, year = 1947, the condition would have to be, for example:
Your initial condition says = If "day" isn't 1 and "month" isn't 1 and "year" isn't 0, only then continue. So it works as intended since parameter "day" is actually 1, and breaks out of the loop. You should read up on negation and logic gates, it will help you understand programming better, since logic gates have been exactly the same for around 100 years.