Repetition in C
Repetition is the process of repeating a set of statements a number of times. C provides 3 ways to perform repetition. They are:
1) for loop
2) while loop
3) do while loop
1) FOR loop
It is the simplest form of repetition in C. It is used to repeat a set of statemnets a fixed number of times. The syntax is:
for ( initialization ; test condition ; increment/decrement )
{
statement;
...
}
Working of for:
1) The counter variable is initialized.
2) Then the test condition is checked. If it is true, then the statements are repeated. If it is false, then control is passed after the for statemnet.
3) If condition is true, then after executing the statementes, it goes for the increment/decrement statement. After that control goes back to statement (2)
No comments:
Post a Comment