HPlogo HP C/HP-UX Reference Manual: Version A.05.55.02 > Chapter 6 Statements

Selection Statements

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Syntax

if (expression) statement [else statement]
switch (expression) statement

Description

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.

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;
    }

© Hewlett-Packard Development Company, L.P.