Swift Playgrounds is displaying an error

I am trying to make a dice rolling simulator but Swift is giving me this error:


error: expected '{' to start the body of for-each loop

for _ in 1...100

^


I am really confused since there is a "{" in my code:


import UIKit


var sum = 0

var dice = 0


for _ in 1...100 {

sum = 0

dice = Int(arc4random_uniform(6))

sum = dice + 1 + sum

dice = Int(arc4random_uniform(6))

sum = dice + 1 + sum

dice = Int(arc4random_uniform(6))

sum = dice + 1 + sum

print (sum)

}


What am I doing wrong?

Replies

You are working with an Xcode Playground on mac, not Swift Playgrounds on iPad, no?


Your code (please try to use `< >` icon in the editing area) works without any problem in my Xcode.

Playground (of Xcode) sometimes keeps old errors and continues showing something like `Running...` in the status bar.

(I haven't waited more than 2 hours, so I do not know if it contines forever...)


Close the Playground window, and restart your Xcode again. Then open your playground file again and see what happens.