January 2018
Intermediate to advanced
434 pages
14h 1m
English
In this example, we will simply create an array of integers and calculate its sum:
fun main(args: Array<String>) { var sum=0 var listOfInteger= arrayOf(0,1,2,3,4,5,6,7) listOfInteger.forEach { sum+=it } println(sum)}
In the preceding example, the sum variable is defined in the outer scope; still, we are able to access and modify it.
Read now
Unlock full access