home > 比較編 > Perl, PHP, Python, Ruby > arrays >

ForNext

Only Do What Only You Can Do

110. indexed iteration

VBScript

JScript

Perl

none; use range iteration from 0 to $#a and use index to look up value in the loop body



PHP

$a = array("do", "re", "mi" "fa");
foreach ($a as $i => $s) {
  echo "$s at index $i\n";
}

Python

a = ['do', 're', 'mi', 'fa']
for i, s in enumerate(a):
  print('%s at index %d' % (s, i))

Ruby

a = %w(do re mi fa)
a.each_with_index do |s,i|
  puts "#{s} at index #{i}"
end

PowerShell

Scala

F#

C

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system