HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 6 Statements

Compound Statement or Block

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Compound or block statements allow you to group other statements together in a block of code.

Syntax

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

declaration-list ::=
declaration
declaration-list declaration

statement-list ::=
statement
statement-list statement

Description

You can group together a set of declarations and statements and use them as if they were a single statement. This grouping is called a compound statement or a block.

Variables and constants declared in the block are local to the block and any subordinate blocks declared therein unless declared extern. If the objects 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 object declared with static storage duration is created and initialized when the program is loaded for execution. This is true even if the object is declared in a subordinate block.

Example

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