Skip to content

Commit dc89d29

Browse files
committed
for loop example
1 parent f3a2be9 commit dc89d29

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// for loop to find sum of numbers from 1 to 10
2+
3+
let sum = 0;
4+
// Using a for loop to iterate from 1 to 10
5+
for (let i = 1; i <= 10; i++) {
6+
// Add the current number to the sum
7+
sum += i;
8+
// Output the current number and sum
9+
console.log("Current number:", i, "Current sum:", sum);
10+
}
11+
console.log("Sum of numbers from 1 to 10 is:", sum); // Output: Sum of numbers from 1 to 10 is: 55

0 commit comments

Comments
 (0)