Skip to content

Seattle CoderDojo

A Free Tech Meetup for Kids

Menu
  • 2023 Reboot
  • Teaching Kids To Code
  • Volunteers
  • Frequently Asked Questions
Menu

Javascript Reboot Lesson 3: Loops

Posted on May 2, 2015May 2, 2015 by Jonathan Ng

Here’s a loop in Scratch:

scratchloop1

Scratch loops have a “repeat” variable that counts the number of times to repeat the loop.  However, Javascript has a way of tracking this variable inside the loop, allowing you to do more things with it.

This is the syntax for a for loop:

for (var i = 0; i < 5; i++)

Each part of the for loop is executed at a specific time.  The first part is supposed to initialize your loop and gets run at the beginning of the loop.  The second part is run at the beginning of each time through the loop and exits the loop if the condition given is false.  The last part of the loop runs at the end of the loop and modifies your loop variable to the next number.

In this case, the loop variable i will start at 0, run through the loop, then go to 1, run through the loop, and so on until it hits 5.  When it goes to 5, it doesn’t run through the loop.

Again, resources for week 3:

  • Crunchzilla’s Code Monster lesson loops (lessons 12-14):http://www.crunchzilla.com/code-monster
  • Khan Academy’s lesson on looping:https://www.khanacademy.org/computing/computer-programming/programming/looping
  • Code Academy’s for loop and while loop lesson:
    http://www.codecademy.com/courses/javascript-beginner-en-NhsaT/0/1?curriculum_id=506324b3a7dffd00020bf661
    http://www.codecademy.com/courses/javascript-beginner-en-ASGIv/0/1?curriculum_id=506324b3a7dffd00020bf661

And assignment for week 3: http://jsfiddle.net/zeroth_hour/nw1um6gn/

 

Upcoming Events

  • CANCELLED: SEATTLE CODERDOJO – March 7, 2020

  • CANCELLED: SEATTLE CODERDOJO – March 14, 2020

  • CANCELLED: SEATTLE CODERDOJO – March 21, 2020

Get News and New Ticket Notices

Join our mailing list. We not only won’t spam you, but you’ll probably complain we don’t mail you enough.

Support Seattle CoderDojo

Make a $5 or $10 donation - not tax deductible.
To make a larger donation ($20 or more) that IS tax deductible, follow this link.
©2023 Seattle CoderDojo | Design: Newspaperly WordPress Theme