Discuss / JavaScript / solution

solution

Topic source

Jevirs

#1 Created at ... [Delete] [Delete and Lock User]
//正序for循环
'use strict';
var arr = ['Bart', 'Lisa', 'Adam'];
for(var i in arr)
{
    alert('Hello,'+arr[i]+'!');
}


//倒序for循环
'use strict';
var arr = ['Bart', 'Lisa', 'Adam'];
for(var i=arr.length-1;i>=0;i--) {
    alert('Hello,'+arr[i]+'!');
}


//正序while循环
'use strict';
var arr = ['Bart', 'Lisa', 'Adam'];
var i=0;
while(arr[i])
{
    alert('Hello,'+arr[i]+'!');
    i++;
}


//倒序while循环
'use strict';
var arr = ['Bart', 'Lisa', 'Adam'];
var i = arr.length-1;
while(arr[i])
{
    alert('Hello,'+arr[i]+'!');
    i--;
}

  • 1

Reply