index.ts182 chars8 lines
In this code snippet, we initialize num
to 1 and use a while loop to print even numbers from 1 to 100. The loop continues as long as num
is less than or equal to 100.
Inside the loop, we check if the number is even by using the modulo operator (%
). If the remainder of num / 2
is 0, it means that the number is even. We print the even number using console.log()
.
Finally, we increment num
to move on to the next number.
gistlibby LogSnag