This blog is under construction

Sunday 29 December 2013

Compound statement

Compound statement is a set of statements or no statements enclosed within set braces. It is also called as blocks.  Compounds statements are usually used in control flow statements(if, if-else, nested if, for, while, do-while etc).

Example 1: 
if (a < b) {
printf("a is less than b");
printf("I am inside compound statement\n");
}
There are two statements inside the if block which are compound statements.

Example 2: 
for (i = 0; i < 5; i++) {

}

There is no statement present inside the for loop.  It is also called as compound statement.

Example 3: 
for (i = 0; i < 5; i++) {
      int j = 10;  // variable declaration
}
Variable declaration is allowed inside blocks.  But, the scope(lifetime) of the variable is only inside the block where it is declared.

Example c program using compound statements
 
  #include <stdio.h>
  int main() {
        int i = 20;

        /* two statements inside if block */
        if (i > 10) {
                printf("Value of i is greater than 20\n");
                printf("Compound statement\n");
        }

        printf("\nBlock with empty statement!! - start\n");
        /* zero statements inside for loop */
        for (i = 0; i < 5; i++) {

        }
        printf("Block with empty statement!! - End\n\n");

        /* variable declaration inside for loop */
        for (i = 0; i < 5; i++) {
                int j = i;
                printf("Value of j is %d\n", j);
        }
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out 
  Value of i is greater than 20
  Compound statement

  Block with empty statement!! - start
  Block with empty statement!! - End

  Value of j is 0
  Value of j is 1
  Value of j is 2
  Value of j is 3
  Value of j is 4



2 comments:

  1. Hello Everyone !

    USA SSN Leads/Dead Fullz available, along with Driving License/ID Number with good connectivity.

    All SSN's are Tested & Verified.

    **DETAILS IN LEADS/FULLZ**

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER
    ->ADDRESS WITH ZIP
    ->PHONE NUMBER, EMAIL
    ->EMPLOYEE DETAILS

    *Price for SSN lead $2
    *You can ask for sample before any deal
    *If you buy in bulk, will give you discount
    *Sampling is just for serious buyers

    ->Hope for the long term business
    ->You can buy for your specific states too

    **Contact 24/7**

    Whatsapp > +923172721122

    Email > leads.sellers1212@gmail.com

    Telegram > @leadsupplier

    ICQ > 752822040

    ReplyDelete
  2. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete