[비교] 반복문 - foreach, for~in

 

 

Java

for (String s : arr) {
    System.out.println("s=" + s);
}

람다?

 

Javascrpt

var person = {fname:"John", lname:"Doe", age:25};
for(x in person){
    txt = txt + ", " + person[x];
}

for (variable in [object | array]) {
    statements
}
--
var arr = ["pantarei", "siliuse", "mir"];  
for(var i = 0 ; i < arr.length ; i++){ 	alert(arr[i]); }  
for(var i in arr){ 	alert(arr[i]); }

 

Python

languages = ['Java', 'Python', 'C']
for language in languages:
    print(language)
}

 

PHP

foreach($customers as $customer){
    echo $customer;
}

 

Perl

여기도 추가
foreach my $string ( @array ) {
    print $string;
}

 

 

JSTL

<c:forEach>

 

Shell

$ for i in 1 2 3
> do
> echo $i
> done
1
2
3

$ for i in 1 2 3; do echo $i; done
1
2
3
$ for n in `find /etc -size 0`; do echo `ls -l $n`; done //xargs를 쓰는게 좋지
 

awk

 

Windows Command

> for %a in (1 2 3) do @echo %a

 

Oracle

FOR - Cursor