Hamilton LaboratoriesHamilton C shell 2012User guideLanguage reference

if and switch

Oregon Coast

if and switch
Previous | Next

Topics

Syntax
if
switch
See also

Syntax

if ( expr ) statement if ( expr ) then statement_list end if ( expr ) then statement_list else statement_list end if ( expr ) then statement_list elif ( expr ) statement if ( expr ) then statement_list elif ( expr ) then statement_list end if ( expr ) then statement_list elif ( expr ) then statement_list else statement_list end switch ( expr ) case expr: statement_list case expr: statement_list default: statement_list end

if

The short form of the if statement, which must be typed on one line, dispenses with the then keyword and accepts a single statement to be executed if expr evaluates as true.

The long form uses a then keyword and allows optional else and elif clauses. The last if in an elif chain may be either a short- or a long-form if statement.

Where an expression is expected, conventional high level language syntax is accepted. Names refer to variables, * means multiply, not wildcard and > means greater than, not i/o redirection.

switch

In a switch statement, expressions are compared by pattern match, as if using the =~ comparison operator. The case expression can be a string with wildcard characters. Comparisons are made down the list of alternatives until one matches. All following statements are executed until a break is encountered. A default clause is optional but is always satisfied if no other case matches.

See also

Statement relationships
Expression operators
Wildcard characters
Tutorial: if and switch
Tutorial: Programming constructs
Tutorial: Expressions
Tutorial: Wildcarding

Previous | Next

Getting started with Hamilton C shell

Hamilton C shell, as it first wakes up.

Getting started with Hamilton C shell

A first few commands.

You can set the screen colors to your taste.

You can set the screen colors to your taste.