Skip to content

Instantly share code, notes, and snippets.

@lizlongnc
Created October 20, 2014 05:43
Show Gist options
  • Save lizlongnc/4da2d50c2dc9222b8534 to your computer and use it in GitHub Desktop.
Save lizlongnc/4da2d50c2dc9222b8534 to your computer and use it in GitHub Desktop.
JS break in for loop
var age = Number(prompt('What is your age? ', ' '));
var string = '';
for (var counter = 1; counter < age; counter++) {
string += 'Happy Birthday\n';
if (counter % 7 === 0) {
break;
}
}
alert(string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment