lundi 24 août 2020

Difference between !(a==b) and a!=b

Last week in high school my IT teacher gave us a programm, where one part she wrote interested me a lot. In an if-statement, she checked if an element of an array was not null, so the programm could proceed with this element, therefore she wrote: if (!(array[i] == null), which confused me, because with this method you are just using a bracket more, which makes it less easy to read. I changed it to ìf (array[i] != null) and it worked just fine. But now I am confused, because as a teacher I assume you know a lot of your subject, so could there be a good reason why she used her method over mine? Is there some detail I don't know about, unfortuantly I can't ask her know and I wouldn't like to do that if I could, would seem kinda dumb...

Aucun commentaire:

Enregistrer un commentaire