Skip to content

Instantly share code, notes, and snippets.

@humayunahmed8
Created June 28, 2018 09:34
Show Gist options
  • Save humayunahmed8/9bb29cc8d6ca5c5eab20c4dc91b23aca to your computer and use it in GitHub Desktop.
Save humayunahmed8/9bb29cc8d6ca5c5eab20c4dc91b23aca to your computer and use it in GitHub Desktop.
JS Loop - For, (While, Do/While, For/In)
/*=====For Loop=====*/
//for (variable; condition; incriment/decriment) {
// Your Document
}
var x;
for (x=56; x<=61; x++) {
document.write(x+'<br/>');
}
/*=====While Loop=====*/
//while (condition) {
// statement
}
var x = 10;
while(x<15){
document.write('Hello World<br/>');
x++;
}
/*=====Do/While Loop=====*/
//do{
// statement
//} while (condition);
var x = 10;
do{
document.write('Hello World<br/>');
x++;
} while (x<18);
/*=====For/In Loop=====*/
//for (variable in object) {
// statement
}
var paragraphElement = document.getElementsByTagName('a');
for(var key in paragraphElement){
document.write(paragraphElement[key].innerHTML+'<br/>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment