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

Branch Statements

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

Syntax

goto label;
goto *expression;
continue;
break;
return [expression];

Description

Branch statements transfer control unconditionally to another place in the executing program. The branch statements are “goto ”, “continue ”, “break ”, and “return ”.

Examples

These four fragments all accomplish the same thing (they print out the multiples of 5 between 1 and 100):

i = 0;
while (i < 100)
{
if (++i % 5)
continue; /* unconditional jump to top of while loop */
printf ("%2d ", i);
}
printf ("\n");

i = 0;
L: while (i < 100)
{
if (++i % 5)
goto L: /* unconditional jump to top of while loop */
printf ("%2d ",i);
}
printf ("\n");


i = 0;
while (1)
{
if ((++i % 5) == 0)
printf ("%2d ", i);
if (i > 100)
break; /* unconditional jump past the while loop */
}
printf ("\n");

i = 0;
while (1)
{
if ((++i % 5) == 0)
printf ("%2d ", i);
if (i > 100) {
printf ("\n");
return; /* unconditional jump to calling function */
}
}

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