lundi 22 février 2016

Confused with the NOT operator when used in if-statements?

func nonZeroAnswer (a : Double, b : Double) -> Bool {

       if a / b == 0 { return true}  else {return false}
 }

nonZeroAnswer (5, 0)   //This returns false

if !nonZeroAnswer(2, 2) {
     print("This is a Zero Answer")
}

I've read the apple documentation over and over and know how the Not operator works and how it inverts a boolean value to its opposite but I don't know how to apply it in more complex code scenarios such as if statements, functions, etc. I don't even know if I wrote this basic program correctly, I'm all in all confused on how to go about writing such a basic program. I'm sorry if this seems like a petty question but I've read the apple documentation and also am studying a swift book that is supposedly for beginners, I've watched numerous youtube videos but just can't wrap my head around using the Not operator in different scenarios other than the ordinary trueValue = True ........ !trueValue //makes it false......That I do understand but furthermore just gets confusing like in this program I've attempted to write above.

Aucun commentaire:

Enregistrer un commentaire