Back to questions
JuniorTheoryCommon
What happens when this program is compiled and run?
var count = 1
let limit = 3
count = 2
limit = 4
print(count, limit)It does not compile
- Expecting
2 4: treatingletlikevar. A constant gets its value once, so the compiler refuseslimit = 4and the program never runs. - Expecting a crash on the line
limit = 4: Swift checks assignments to constants while compiling, before a single line runs.
- What does the program print if
limitis declared withvar? - Why does the compiler report the error before the program can print
count?