Loops

Loops
πŸ‘¨β€πŸ’Ό Let's practice a simple for loop by building a numbered list.
🐨 Open
index.ts
and use a for loop to build a string with labels for exhibits 1 through 5. Each label should be on its own line.

How a for loop works

for (let i = 0; i < limit; i++) {
	// repeat work
}
Each part of the loop has a job:
  • Initializer (let i = 0) runs once before the loop starts
  • Condition (i < limit) is checked before each iteration
  • Final expression (i++) runs after each iteration
i++ means "add 1 to i." It's the same as i += 1.
πŸ“œ MDN - for...of (an alternative loop syntax you'll see in the wild)

Please set the playground first

Loading "Loops"
Loading "Loops"