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

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...