Swift Ternary Operator
myBool = str1 != nil ? true : false
print(myBool)
3.5
2
let a = 10
// Note that the space after the question mark
// is required! If you don't do this, the compiler
// will think you're trying to use optional chaining.
let result = a > 5 ? true : false // true
Thank you!
2
0
4.25
8
// Ternary operator ==>
// value = condition ? valueIfTrue : valueIfFalse
Thank you!
8
0
3.33
3
// program to check pass or fail
let marks = 60
// use of ternary operator
let result = (marks >= 40) ? "pass" : "fail"
print("You " + result + " the exam")
Thank you!
3
0
0
0
let grade = "F<br/><br/><br/>let gradeA = grade == "A" ? "Congratulation! Your Score Is Excellence,Keep It Up" <br/> : grade == "B" ? "Your Grade Is Good But You Have Need Small Improvment"<br/> : grade == "C" ? "You Need Improve In Some Subjects"<br/> : grade == "D" ? "You Have Need To More Study For Improvment " : "You Fail Better Luck Next Time"<br/><br/>print(gradeA)<br/><br/>//Ans :You Fail Better Luck Next Time
Thank you!
0
0
Are there any code examples left?
New code examples in category Swift
-
Swift 2022-03-27 20:55:05 swift sleep milliseconds
-
Swift 2022-03-27 18:20:18 swift how to call a function
-
Swift 2022-03-27 13:40:24 swift loop through array
-
Swift 2022-03-27 06:15:23 swift image button blue
-
Swift 2022-03-25 03:15:09 Finger Print in Swift
-
Swift 2022-03-25 02:20:26 swift save data to file
-
Swift 2022-03-25 00:20:01 closure swift
-
Swift 2022-03-24 13:45:28 change textview link color swift
-
Swift 2022-03-19 12:45:01 swift uitextfield only numbers keyboard lock programmatically
-
Swift 2022-03-18 00:25:20 how to read music library from iphone programmatically in swift