🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C Notes
Topic #49

Array Loops


Loop Through an Array

You can use a for loop to go through the elements of an array by writing the size of the array in the loop condition (in this example the array has 4 elements, so we use i < 4). However, this is not ideal, since it will only work for arrays of a specified size:

Example

int myNumbers[] = {25, 50, 75, 100};
int i;

for (i = 0; i < 4; i++) {
  printf("%d\n", myNumbers[i]);
}

Making Better Loops

In the previous chapter, you learned how to calculate the number of elements in an array using the sizeof formula. Now we can use that to write loops that work for arrays of any size. This is more flexible and sustainable:

Example

int myNumbers[] = {25, 50, 75, 100};

int length = sizeof(myNumbers) / sizeof(myNumbers[0]);
int i;

for (i = 0; i < length; i++) {
  printf("%d\n", myNumbers[i]);
}

This loop will automatically work no matter how many elements the array has!

Note: Summary: Always use the sizeof formula when looping through arrays. It makes your loops adapt to the array size automatically.

Want to go beyond the notes?

Join CodingNow 2.0's C course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Array Loops – FAQs

Quick answers about learning Array Loops in C.

This free note from CodingNow 2.0 explains Array Loops in C — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C topic on CodingNow 2.0, including Array Loops, is 100% free with no signup required.
With focused practice, most students grasp Array Loops in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now