HPlogo HP C/HP-UX Reference Manual: Version A.05.55.02 > Chapter 6 Statements

Compound Statement or Block

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Syntax

compound-statement ::=
{[declaration-list][statement-list]}

declaration-list ::=
declaration
declaration-list declaration

statement-list ::=
statement
statement-list statement

Description

A compound statement allows you to group statements together in a block of code and use them as if they were a single statement.

Variables and constants declared in the block are local to the block and to any inner blocks unless declared extern. If the variables are initialized, the initialization is performed each time the compound statement is entered from the top through the left brace ({) character. If the statement is entered via a goto statement or in a switch statement, the initialization is not performed.

Any variable declared with static storage scope is created and initialized when the program is loaded for execution. This is true even if the variable is declared in an inner block.

Example

if (x > y)
{
int temp;
  temp = x;
  x = y;
  y = temp;
}

In this example, variable temp is local to the compound statement. It can only be accessed within the compound statement.

© Hewlett-Packard Development Company, L.P.