From f771c37ccb87c6ac737badd299bbf2d07737a351 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 22 Aug 2016 08:20:18 -0400 Subject: [PATCH] loops --- javascript.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/javascript.md b/javascript.md index db9d55a..d1f18e3 100644 --- a/javascript.md +++ b/javascript.md @@ -174,6 +174,26 @@ if(1 === 2){ } ``` +## Loops + +We can repeat a block of code over and over again while a certain statement is true + +```javascript +var i = 1; +while(i < 5){ + console.log(i); + i++; +} +``` + +We can use `for` loops as a shorthand for the above + +```javascript +for(var i = 1; i < 5; i++){ + console.log(i); +} +``` + ## Functions are objects Functions can be assigned to variables