ForNext
Only Do What Only You Can Do
147. multiple return values
Hyperpolyglot Interpreted Languages: PHP, Perl, Python, Ruby より (2012.05.08)
VBScript
JScript
Perl
sub first_and_second { return ($_[0], $_[1]); } @a = (1,2,3); ($x, $y) = first_and_second(@a);
PHP
function first_and_second(&$a) { return array($a[0], $a[1]); } $a = array(1,2,3); list($x, $y) = first_and_second($a);
Python
def first_and_second(a): return a[0], a[1] x, y = first_and_second([1,2,3])
Ruby
def first_and_second(a) return a[0], a[1] end x, y = first_and_second([1,2,3])