Repetitive statements in C
In programming practices, we may need to execute one or a few statements more than once. Say we want to add two or more numbers or want to know the average of those numbers. Now we need to add numbers one by one and calculate the final summation.
We can have two or three statements to add few numbers but the total count of numbers may be any positive numbers ranging 1-10, 1-100, or more. So basically the number of count is a variable in nature and the program should be flexible enough to deal with this total count. To make it generic we need to alter the programming logic. We can take the numbers in an array and add the array elements till the count is reached
These type of requirement in the programming can be achieved by loop statements.
Loop statements
In the programming world, repetitive statements can be executed with the help of loop statements. C/C++ and all modern programming languages have basic loop statements to do repetitive statements.
Writing repetitive statements is easy in C and keywords like for, while, do-while are available for this. Let us discuss these three types of looping statements one by one.
Repetitive statements with FOR
For loop is a basic loop statement used very often in programming.
Repetitive statements with WHILE
While loop does not have any initial statement like for loop. It goes straightly to condition checking then executes statements and again comes to condition checking. Thus again it does not have any step statement.
While loop is good when we do not know when to end specifically like linked list iterations.
Repetitive statements with DO-WHILE
For do-while has this syntax-
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average