JavaScript 'For Loops'

A little glimpse into JavaScript 'For Loops'. 


Code:

arr = ['Fortran', 'Python', 'C++', 'Assembly', 'Binary'];

for (x in arr) {
document.write(x);
}
document.write('<br>');
for (var i = 0; i < arr.length; i++) {
document.write(i);
}
document.write('<br>');
for (x of arr) {
document.write(x + ' ');
}
document.write('<br>');
for (var i = 0; i < arr.length; i++) {
document.write(arr[i] + ' ');
}

Result:

01234
01234
Fortran Python C++ Assembly Binary
Fortran Python C++ Assembly Binary

No comments:

Post a Comment

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...