Loop: A segment of the program that is created repeatedly is called as a loop. The loop concept is essential.It is fundamental for good programming.
A looping process generally has the following steps. Step 1: Setting and initialization of the counter i.e., loop control variable Step 2: Test for a specified condition for execution of the statements in the loop. Step 3: Incrementing or decrementing the counter. |
Use of a Loop Structure
Some potion of the program has to be specified number of times or until a particular condition is satisfied. such repetitive operation is done through a loop structure. |
Components of for-loop with a Single Statement
1) Keyword 'for' 2) ( Parenthesis 3) InitializationPart 4) TestConditionPart 5) IncrementorDecrementPart 6) ) Closing Parenthesis 7) Statement Components of for-loop with Multiple Statements
1) Keyword 'for' 2) ( Parenthesis 3) InitializationPart 4) TestConditionPart 5) IncrementorDecrementPart 6) ) Closing Parenthesis 7) { Opening brace 8) Multiple Statements 9) } Loop Control Variable
for loop Variations
The for-loop supports a number of variations that increase its power and applicability. The reason it is so flexible is that its three parts.
University Questions
1. Describe the use of for statement and explain how is differs from for statement and do-while statement? (April 2009)
2. What are nested control structures? Give an example. Apr 09 3. Specify the syntax used for ‘for’ statement (April 2009) 4. Explain the general syntax of ‘for’ statement with an example (April 2009) 5. Explain the FOR loop with examples. (April 2008) 6. What is the difference between while and for loop. (Nov 2005) 7. Explain LOOP controls with suitable examples in C (April 2005) Programs 1. Write a program to check whether the given number is prime or not? (April 2009) 2. Write a C program for matrix multiplication. (April 2009) 3. Write a C program to count the number of digits of the given integer number. (April 2009) 4. Write a C program to find the sum of N given numbers. (Nov 09) 5. Write a C program to find the sum of the series 5+15+25+..+95 (April 2008) 6. Write C program to multiply two matrices of order m*n and n * l (Apr 2008) 7. Write a C program to find the digit sum of a positive integer (Nov 2008) 8 . Write a C program to check whether the given square matrix is (Nov 008) an identify matrix. 9. Write a C program to find the factorial value of a given integer(April 2007) 10. Write a program in C to read the given matrices A and B and (April 2003) and print the product of two matrices. 11. Write a C program to transpose a matrix. (November 2003) 12. Write a C program to find the value of x raised to the power N (April 2002) where x and n are integers. 13. Generate a C program to multiply a given n * n matrix. (April 2001) |
General form of for-loop with a single statement
for(InitializationPart;TestConditionPart; IncrementorDecrementPart)
Statement; General form of for-loop with multiple statements
for(InitializationPart;TestConditionPart; IncrementorDecrementPart)
{ Statement; Statement; Statement; } Definition of InitializationPart
Definition of TestConditionPart
Definition of Iteration or IncrementorDecrementPart Definition of Body of the Loop |