A
A
allaga2019-05-27 09:01:04
Swift
allaga, 2019-05-27 09:01:04

How does a constant work inside a "for" loop?

Good afternoon!
Swift code:

for count in 1...5 {
     let a = count
     print(a)
}

Why, in this scenario, does the constant a change its value during the loop? Or is it re-announced each time? Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Vorobei, 2019-05-27
@allaga

In each cycle , the constant is re-declared . When exiting the loop, it is removed from memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question