Sheerpower Logo
E.6  Enum Statement
The ENUM (enumerated) statement creates a cluster where each member is assigned a sequential number starting at one.

size(clustername,2) returns the number of members in the enum. ENUM is useful when making "state machines" and other situations where assigning sequence numbers to a series of variable names is desired.

Example: Traffic Light States

This example demonstrates how to use the Enum statement to define traffic light states and handle them using a Select Case statement.

Enum traffic_light: red, yellow, green current_state = traffic_light->yellow select case current_state case traffic_light->red print "Stop" case traffic_light->yellow print "Get Ready" case traffic_light->green print "Go" case else print "Unknown State" end select // number of members of the enum, three in this case print 'Number of members: '; size(traffic_light,2)

Explanation

This example creates an Enum for traffic light states and uses a Select Case statement to print messages based on the current state of the traffic light. Each case corresponds to a different state defined in the enum.

Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.
Wide screen