C ยท Lesson 3 of 3

๐Ÿ” Loops in C

Repeat code with for loops.

A for loop in C looks just like Java: start, condition and step.

#include <stdio.h>

int main() {
    for (int i = 1; i <= 5; i++) {
        printf("%d squared is %d\n", i, i * i);
    }
    return 0;
}
OUTPUT1 squared is 1 2 squared is 4 3 squared is 9 4 squared is 16 5 squared is 25

โœ๏ธ Your turn

Open this example in the playground, change it and run it.

โ–ถ Try it yourself

๐Ÿง  Quick quiz

What does i-- do?