Looping over a list of values one at a time, two at a time and more
Missing values
Looping over any number of elementsYou can also iterate over any number of elements: Let's say we just extracted the results of the Spanish Liga football games from the soccer website http://soccernet.espn.go.com/ . Those come in groups of 4 values: home team, score of home team score of guest team guest team We can loop over the values using a for statement with 4 scalar variables: examples/arrays/looping_over_many_elements.p6#!/usr/bin/perl6
use v6;
my @scores = <
Valencia 1 1 Recreativo_Huelva
Athletic_Bilbao 2 5 Real_Madrid
Malaga 2 2 Sevilla_FC
Sporting_Gijon 3 2 Deportivo_La_Coruna
Valladolid 1 0 Getafe
Real_Betis 0 0 Osasuna
Racing_Santander 5 0 Numancia
Espanyol 3 3 Mallorca
Atletico_Madrid 3 2 Villarreal
Almeria 0 2 Barcelona
>;
for @scores -> $home, $home_score, $guest_score, $guest {
say "$home $guest $home_score : $guest_score";
}
Copyright 2006, 2007, 2008, 2009, 2010 Gabor Szabo http://szabgab.com/ Index | TOC |
Follow me: