Iterando en array / Iterating over an array

/*Simple for in Loop*/ for animal in animalArray { println(animal) } //Prints each animal name into the console. /*for in Loop + Enumeration*/ /*If you want to have the index of the item as well, you must use the enumerate function with your loop. The enumerate function returns a Tuple for each value in the array.*/ for(index,animal) in enumerate(animalArray) { println("The \(animal) is at index:\(index)") } //Output: //The Dog is at index:0 //The Cat is at index:1 //The Fish is at index:2 //The Owl is at index:3

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.