Control Flows in Swift

Use if and switch to make conditionals, and use for-in, while, and repeat-while to make loops.

let subjectMarks = [75, 43, 103, 87, 12]

for grade in subjectMarks {

    if grade > 50 {


    } else {




Switches support any kind of data and a wide variety of comparison operations—they aren’t limited to integers and tests for equality.

let javascript_libs = "ReactJs"

switch javascript_libs {

case "Jquery", "html":

    print("That would make a html webpage.")

case let x where x.hasSuffix("Js"):

    print("Is it a Javascript library \(x)?")


    print(“Everything is needed for web development.")


Leave a Reply

Your email address will not be published. Required fields are marked *