Home FOR LOOP SYNTAX IN C

FOR LOOP SYNTAX IN C

for loop in c, for loop c programming, for loop syntax in c, for loop in c programming example, for loop example in c, for loop c programming practice

There are some situations statements are executed repeatedly until condition is false. In such cases we can use looping statements.

When implement the looping process it must be involve the following four points:

1. Initialization of counter value.

2.test for the specified condition.

3.execute the statements in the loop. (body of loop)

4.based on condition increment or decrement.

To implement looping process C language supports three looping statements.

1. for statement

2. while statement

3. do..while statement

1. for Statement:

In all looping statements, for statement is mostly used. The general syntax of for statement is:

Syntax:

for(initilization; condition; increment/decrement)

{

body of loop;

}

ex:

for(i=0;i<5;i++)

{

printf(“Ekvij.com\n”);

}

For above code output will

Ekvij.com

Ekvij.com

Ekvij.com

Ekvij.com

Ekvij.com

2. while Statement:

In all looping statements, while statement is simplest. The general syntax of while statement is:

Syntax:

initilization;

while(condition)

{

body of loop;

increment or decrement;

}

ex:

i=1;

while(i<=10)

{

printf(“Welcome”);

i++;

}

3. DO..WHILE STATEMENT:

This is another loop statement, supported by C language. It is also perform the looping operations. The general syntax of do..while statement is as follows:

Syntax:

initilization;

do

{

body of loop;

increment or decre;

}while(condition);

When ever execute the do..while statement first initilize the value. Then execute the body of the loop. Once body is executed then check the condition. If it is true once again execute the body of loop. This process unitl condition is false. Once false the condition program out of the loop.

The main Difference between while and do..while statement is, in while, when ever condition is true,then execute the statements in the loop. where as in do..while first execute the statements in the loop, then check the condition. if it is true once again execute the loop, until condition false.

ex:

i=1;

do

{

printf(“%d\n”,i);

i++;

}while(i<=10);

Some examples are given below to exicute by using looping statements.

1. WAP print sum of first 10 natural numbers.

2. WAP reverse of given number.

3. WAP findout the factorial of given number.

4. WAP Armstrong number or not.

c programming

c programming or C is a procedural programming language.

c programming was initially developed by Dennis Ritchie in the year 1972.

c programming was mainly developed as a system programming language to write an operating system.

The main features of C language or c programming include low-level access to memory, a simple set of keywords, and clean style, these features make C language suitable for system programmings like an operating system or compiler development.

Many later languages have borrowed syntax/features directly or indirectly from C language.

Like syntax of Java, PHP, JavaScript, and many other languages are mainly based on C language.

C++ is nearly a super set of C language (There are few programs that may compile in C, but not in C++).