TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C Tutorials

C for loop statement

Overview

C for loop statement allows us to repeat a statement or group of statements more than once. The programmer can use this loop when the number of iterations is known beforehand. For example, to iterate over the array elements of fixed size.

Syntax

The general syntax for the C for loop is as follows:

for (loop initialization; condition; increment/decrement)
{
// for loop statements
}

Example

Sample program to illustrate the for loop in C language.

 

/**
**********************************
* Program Description:
* C for Loop Statement Demo
* Filename : forDemo.c
* C Tutorials – www.TestingDocs.com
*************************************
*/
#include<stdio.h>
int main()
{
int i;// for loop counter variable

for(i= 1; i<= 10; i++)// C for loop statement
{
printf(” Loop Iteration (%d) \n”,i);
} // end for loop

return 0;
} // end main

—

C for loop statement

In this example, we have declared a for loop counter variable i.  The loop executes 10 times. The loop executes for values i <= 10. When the variable i reaches 11 the loop condition i <= 10 is false. The loop will exit.

Output

C for loop output example

—

C Tutorials

C Tutorials on this website can be found at:

https://www.testingdocs.com/c-language-tutorial/

Related Posts

C Language Characteristics

C Tutorials /

C Language Characteristics

C Source Code .c File

C Tutorials /

C Program Files & Formats

GNU Compiler Collection GCC

C Tutorials /

C Compilers

C Pointers

C Tutorials /

C Pointers

C Tutorials /

C Two-Dimensional Arrays

‹ C if Statement› C scanf Function

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version