Repetition
Repetition, or widely known as looping, are a way to run a block of program again and again until a certain condition has been fullfilled. These are the types of repetition used in C programming: -) for loop : The syntax of for loop is: for (initializationStatement; testExpression; updateStatement) { // codes } The initialization statement is executed only once. Then, the test expression is evaluated. If the test expression is false (0), for loop is terminated. But if the test expression is true (nonzero), codes inside the body of for loop is executed and the update expression is updated. This process repeats until the test expression is false. The for loop is commonly used when the number of iterations is known. for loop flowchart: for loop example: // Program to calculate the sum of first n natural numbers // Positive integers 1,2,3...n are known as natural numbers #include <stdio.h> int main...
Comments
Post a Comment