# Loops in canvas in JavaScript

Drawing on canvas can be put into a loop. Let's draw some lines with a loop:

`<canvas width="200" height="200" style="background: #f4f4f4;"></canvas>` `let canvas = document.querySelector('canvas'); let ctx = canvas.getContext('2d'); for (let i = 1; i <= 10; i++) { ctx.moveTo(50, 15 * i); ctx.lineTo(150, 15 * i); } ctx.stroke();`

:

## Practical tasks

← →
↑
en ru