Lesson 7 of 23

The for Loop

8 min 25 XP

for (start; condition; step) runs while the condition is true. It is the building block for sums, multiplication tables and factorials.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Use long long for big numbers and print it with %lld. An int only goes up to about 2 billion.

Challenge

+25 XP

Read n and print the sum of the even numbers from 1 to n. Input: 10 → Output: 30

Output Loading C (first time takes a few seconds)
Press Run to see the result here.