for (let i = 0; i < 10; i--) {
// 'i' starts at 0 and keeps decreasing (0, -1, -2, ...),
// so the condition 'i < 10' is always true.
}
======================
for (;;) {
// Code to be executed indefinitely
}
==================
for (let i = 0; true; i++) {
// This condition is always true
}
====================
for (let i = 0; i !== 10; i += 2) {
// 'i' takes values 0, 2, 4, 6, 8, 10, 12...
// The condition 'i !== 10' is true for all these values,
// including 10 because the exact value of 10 is skipped.
// Better to use '<=' or '>=' for numeric range conditions.
}
No comments:
Post a Comment