Type of Loops
Sat Aug 13 2022 15:02:06 GMT+0000 (Coordinated Universal Time)
Saved by
@codewithapollo
#javascript
FOR LOOPS
for (inital expression; condition; increment) {
statements
}
use (i)for index
for (let i = 10; i >= 1; i--) {
if (i % 2 !== 2) console.log(i)
}
FOR IN LOOPS
const device = {
brand: 'Acer',
model: 'TMP12-322',
specs: {
ram: 8,
rom: 256
}
}
for (key in device.specs) {
console.log(key, device.specs[key])
}
// LOOP CONTROL
for (let i = 1; i <= 10; i++) {
if (i == 5)
// the counting will stop less than 5
break;
console.log(i)
}
content_copyCOPY
Comments