while (condition) { }do { } while (condition);: runs at least oncefor (int i = 0; i < n; i++) { }
break leaves a loop and continue skips to the next iteration. Loops can be nested.
while, do-while and for.
✍️ 2 exercises in this lessonwhile (condition) { }do { } while (condition);: runs at least oncefor (int i = 0; i < n; i++) { }break leaves a loop and continue skips to the next iteration. Loops can be nested.
Mastering C Loops helps you write clean and reliable C code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
printf("%d x 3 = %d\n", i, i * 3);
}
int n = 1;
while (n < 100) n *= 2;
printf("First power of 2 >= 100: %d\n", n);
for (int row = 1; row <= 3; row++) {
for (int col = 1; col <= row; col++) printf("*");
printf("\n");
}
return 0;
}
1 x 3 = 3 2 x 3 = 6 3 x 3 = 9 4 x 3 = 12 5 x 3 = 15 First power of 2 >= 100: 128 * ** ***
Check what you learned in “C Loops”.
Write a for loop header that counts from 0 to 4.
for (int i = 0; i 5; i++)
Which loop checks its condition after running once?
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services