funcunlockPaidItem(){letuserSubscribed=getSubscriptionStatus()guarduserSubscribedelse{showAlert("You have not subscribed yet!")// Forget to return here!}paidItem.unlock()}// error: 'guard' body must not fall through,// consider using a 'return' or 'throw' to exit the scope
letage=21switchage{case0:print("New born")case1..<10:print("Child")case1..<25:print("Young people")default:print("I don't care about it right now")}// Young People
forcharacterin"Swift Programming Language"{ifcharacter==" "{print("Blank character exists!")break}}
使用标签跨越多层循环进行控制:
1 2 3 4 5 6 7 8 9101112131415
letwords=["Swift","烫","Programming","Language"]outerLoop:forwordinwords{// A stupid switch just to demostrateswitchword.first{case"S":print("Swift")case"P":print("Programming")case"L":print("Language")default:print("Invalid word!")breakouterLoop}}// Swift// Invalid word!