If Statement in Swift 3

September 27, 2017

Lets see how we can write the If statement in Swift 3
This example show how student gets pass for his subject according to marks

If student has marks over 75 he gets A pass
If student has marks less than 75 and more than 65 he gets B pass
If student has marks less than 65 and more than 55 he gets C pass
If student has marks below 55 he is failed the subject

var marks: Int = 57
if( marks >= 75 ){
    print("You have A Pass")
} else if ( (65 < marks) && (marks < 75) ){
    print("You have B Pass")
} else if ( (55 < marks) && (marks < 65) ){
    print ("You have C Pass")
} else{
    print ("Sorry, You failed")
}

Output
You have C Pass