Example #1



var usernameValid = true

var passwordValid = true

if usernameValid && passwordValid {

    print("Welcome back!")

} else if !usernameValid && !passwordValid {

    print("Username and password are not valid, please try again.")

} else if !usernameValid {

    print("Invalid username, please try again.")

} else if !passwordValid {

    print("Invalid password, please try again.")

}


NOTE: (!) in front of a variable "!usernameValid" for example, immediately makes it false. 

Example #2



let username = "Robert"

let password = "mypassword"

if username == "Robert" && password == "mypassword" {

    print("Welcome " + username + "!")

} else if username != "Robert" && password != "mypassword" {

    print("Username and password invalid, please try again.")

} else if username == "Robert" {

    print("Invalid password, please try again.")

} else {

    print("Invalid username, please try again.")

}


Happy coding!