APSC 160 Chapter 4.9: LOOPS IN C
Document Summary
If you want to execute any statement or block of code more than once or multiple times, then we use loop in programming language. The purpose of loop is to avoid repetition of same code multiple times. Hence the code becomes less tedious and more understandable. There are three kinds of loops in c. they are for loop, while loop and do-while loop. All perform the same task and return the same output but the syntax is different. Here is a sample example/code which just prints the numbers from 1 10 on the screen using for loop. #include int main() for (int i = 1; i <= 10; i++){ printf( %d , i); return 0; Here is how it works: there are basically three parts in for loop. Here we declared the variable i and initialized its value to 1. It check every time for 10 times whether the condition is true.