swift - Let type in a for in loop -


i'm playing around swift. why possible declare let type in loop? far know, let means constant, i'm confused.

    func returnpossibletips() -> [int : double] {         let possibletipsinferred = [0.15, 0.18, 0.20]         //let possibletipsexplicit:[double] = [0.15, 0.18, 0.20]          var retval = dictionary<int, double>()         possibletip in possibletipsinferred {             let inpct = int(possibletip * 100)             retval[inpct] = calctipwithtippct(possibletip)         }      return retval      } 

the lifespan of inpct constant during loop iteration since block scoped:

for in 1...5 {     let x = 5 } println(x) // compile error - use of unresolved identifier x 

in every iteration inpct refers new variable. can not assign of inpcts in iteration since declared let:

for in 1...5 {     let x = 5     x = 6 // compile error } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -