Loops are used to repeat a block of code multiple times.
#includeint main() { for (int i = 1; i <= 5; i++) { printf("Count: %d\n", i); } return 0; }
This program uses a for
loop to print numbers from 1 to 5.
#includeint main() { int i = 1; while (i <= 5) { printf("Count: %d\n", i); i++; } return 0; }
This program uses a while
loop to print numbers from 1 to 5.