APSC 160 Chapter 4.9: LOOPS IN C

79 views2 pages
31 Aug 2016
School
Department
Course

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.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents