Reputation: 630
I am going through the new Apple Swift language.
Why should I use variable name at the end ?
var largest = 0
for (kind, numbers) in interestingNumbers {
for number in numbers {
if number > largest {
largest = number
}
}
}
largest
Upvotes: 1
Views: 199
Reputation: 401
If you are following the learning book (I see the code sample taken from the iBook) without Xcode; you are missing Xcode's Playground.
Download Xcode 6 Beta, open playground, paste above code, see the magic ;-)
Playground is a tool to see what happens in your code as you type.
Also to understand the philosophy behind Xcode Playground take a look at this video:
Bret Victor - Inventing on Principle http://vimeo.com/36579366
Upvotes: 0
Reputation: 64684
Are you asking why the last line is largest
? Paste the code into a playground and you'll see it show the value of largest on the right at that line. It's just so you can see what the value is after the loop.
Upvotes: 4