【Todo】各种语言里面的for循环 & loop

会的语言多了,不同语言的语法就会混淆。整理了一下。

 

Java里面:

普通的for循环之外;

有以下格式:

for (int x : intarr) {
}

 

JS里面:

var person={fname:"John",lname:"Doe",age:25};

for (x in person)
  {
  txt=txt + person[x];
  }

 

C++ 11里面:

int arr[] = {1,2,3,4,5};

for(int& e : arr)
{
  e = e*e;
}

 

PHP里面:

有普通for循环;另外:

for ($item_array as $item) {

}

 

Scala里面:

for (i <- 1 to 10) {
}
会打印10个(1到10)

until也可以:
for (i <- 1 until 10) {
}
会打印9个,(1到9,不包括10)

加条件:
for (i <- 1 to 10 if i % 2 == 0) {
}
打印偶数

 

posted @ 2016-11-15 13:56  blcblc  阅读(610)  评论(0编辑  收藏  举报