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

Jump Statements

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Jump statements cause the unconditional transfer of control to another place in the executing program.

Syntax

jump-statement ::=
goto identifier;
continue;
break;
return [expression];

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 */
}
}