TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Day six, loops

Forums > 100 Days of SwiftUI


let platforms = ["iOS", "macOS", "tvOS", "watchOS"]

for os in platforms {
    print("Swift works great on \(os).")
}

When I run the code above in playground, it prints the final element of the array only. When run my output is:

Array of 4 String elements
[several blank lines]
 "Swift works great on watchOS.\n"

Expected behavior?

Sonoma 14.2, Xcode 15.0.1

edit: running the swift code from the command-line displays each element.

2      

When I run in playground, get this

Swift works great on iOS.
Swift works great on macOS.
Swift works great on tvOS.
Swift works great on watchOS.

2      

Thanks for the reply,

I'm not allowed to insert an image or to link to an image, unfortunately. I wanted to show exactly what I was seeing

I have two panels:

The left-hand panel, where I'm entering code, has line-numbers. The right-hand panel shows only partial output.

the screencap can be seen at http // jocala dot com / play.png

2      

You need to show the debug area. You can do this under the View menu, or using ⇧⌘Y

2      

See this

Playgroung

PS to insert image I use Dropbox (allowed link) and then change the last bit of url (dl=0) to raw=1 then it should work

3      

Thanks! I'm all sorted out and proceeding onward. Day seven!

2      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.