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

Selection Statements

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

A selection statement alters a program's execution flow by selecting one path from a collection based on a specified controlling expression. The if statement and the switch statement are selection statements.

Syntax

selection-statement ::=
if (expression) statement
if (expression) statement else statement
switch (expression) statement

Examples

if (expression) statement:

if (x<y) x=y;

if (expression) statement else statement:

if (x<y) x=y; else y=x;

switch (expression) statement:

switch (x)
{ case 1: x=y;
break;
default: y=x;
break;
}