For – loop in C

  • ‘For’ is an Iterative type control statement, which means that it works as a loop.
  • Syntax :
for (Initilization;Condition;Control variable Operation)
{
              Statement 1;
              Statement 2;
               ...
}

 

A process of ‘for’ loop execution :

  1. Initialization.
  2. Condition check.
  3. Statement execution.
  4. Control Variable Operations.
  5. (increment/decrement operations).

 

For example :

main()
{
    int i ;
    for(i=0;i<3;i++)       <<---- Don't put semicolon( ; )after for loop
    {
             printf("hello .... i = %d\n",i);
    }
             printf("hi .... i = %d \n",i);
}

Answer :  hello .... i = 0
          hello .... i = 1
          hello .... i = 2
          hi .... i = 3

 

Example : for (i = 0 , i < 3 , i++);

> If you will put a semi colon after ‘for’ loop it will execute but the statement will not execute. When the condition becomes a false statement then it will execute a statement.

 

 

 

 

 

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: