Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP C/HP-UX Reference Manual: HP-UX Systems > Chapter 6 Statements

break

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

Syntax

break;

Description

A break statement terminates the execution of the most tightly enclosing “switch ” statement or “for ”, “while ” , “do...while ” loop.

Control passes to the statement following the switch or iteration statement. You cannot use a break statement unless it is enclosed in a switch or loop statement. Further, a break only exits out of one level of switch or loop statement. To exit from more than one level, you must use a goto statement.

When used in the switch statement, break normally terminates each case statement. If you use no break (or other unconditional transfer of control), each statement labeled with case flows into the next. Although not required, a break is usually placed at the end of the last case statement. This reduces the possibility of errors when inserting additional cases at a later time.

Example

The following example uses break to exit from the for loop after executing the loop three times:

for (i=0; i<=6; i++)
if(i==3) break;
else printf ("%d\n",i);

This example prints:

     0
     1
     2

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.