-
Notifications
You must be signed in to change notification settings - Fork 0
irxground edited this page Sep 9, 2013
·
6 revisions
各言語における for
および foreach
を比較する。
int i;
for (i = 0; i < SIZE; i++) {
sum += i;
}
for (Item *item = list; item != NULL; item++) {
sum += p->value;
}
誰か書いて
for (int i = 0; i < list.length; i++) {
sum += list[i];
}
for (Item item : list) {
sum += item.value
}
foreach (var item in list) {
sum += item.Value;
}
use reduce
sum += list.Aggrigate(0, item => sum + item.Value)
# 推奨されない
for i in 0 ... MAX
sum += i
end
# better
(0...MAX).each do |i|; end
MAX.times do |i|; end
list.each do |item|
sum += item.value
end
sum += list.inject(0){ |sum, item| sum + item.value }
foreach($list as $item) {
$sum += $item->value
}
sum = sumList' 0 list
where
sumList' sum [] = sum
sumList' sum (x:xs) = sumList' (sum + value x) xs
integer i, sum
sum = 0
DO i = 1, 10
sum = sum + i
END DO
FOR i = 1 TO 10
sum = sum + i
NEXT i