js 循环

1. for 循环

for (var i=0; i<5; i++)
  {
  console.log('hello');
  }

2. for in 循环

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

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

3.  while 循环

while (i<5)
  {
  x=x + "The number is " + i + "<br>";
  i++;
  }

cars=["BMW","Volvo","Saab","Ford"];
var i=0;
for (;cars[i];)
{
document.write(cars[i] + "<br>");
i++;
}

4.  do/while 循环  

do
  {
  x=x + "The number is " + i + "<br>";
  i++;
  }
while (i<5);

1.for循环

1.for循环

1.for循环

1.for循环

猜你喜欢

转载自www.cnblogs.com/justSmile2/p/9456916.html