Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Programming

The switch .. case ... statement

 

Control Structures

The switch .. case ... statement

The switch statement can deal with specific values for the control variable. Typically we can use integers or enumerated types.

See also: Boxes tutorial
See also: if .. else ..
See also: if .. else .. if ..

1. [ Java ] switch .. case


Big

We calculate the population density in people per 100km2.

  • Notice that each case requires the break
  • Notice that cases 2 and 3 have been combined.
  • Notice that the default condition can be specified.