Enumerations

From Rosetta Code
Revision as of 03:16, 23 February 2007 by 74.56.102.15 (talk) (New page: {{task}} <div class="messagebox"> Create an enumeration of types with and without values. </div> ==BASIC== Category:BASIC '''Interpeter:''' QuickBasic 4.5, PB 7.1 REM Impo...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Enumerations
You are encouraged to solve this task according to the task description, using any language you may know.

Create an enumeration of types with and without values.

BASIC

Interpeter: QuickBasic 4.5, PB 7.1

 REM Impossible. Can only faked with arrays of strings.

C

Compiler: GCC, MSVC, BCC, Watcom

Libraries: Standard

 enum fruits { apple, banana, cherry };
 enum fruits { apple = 0, banana = 1, cherry = 2 };

C++

Compiler: GCC, Visual C++, BCC, Watcom

 enum fruits { apple, banana, cherry };
 enum fruits { apple = 0, banana = 1, cherry = 2 };

C#

 enum fruits { apple, banana, cherry }
 enum fruits { apple = 0, banana = 1, cherry = 2 }
 enum fruits : int { apple = 0, banana = 1, cherry = 2 }

D

Compiler: DMD,GDC

Forth

Fortran

Java

Java 1.5 only

 enum fruits { apple, banana, cherry };
 enum fruits { apple = 0, banana = 1, cherry = 2 };

JavaScript

 enum fruits { apple, banana, cherry };
 enum fruits { apple = 0, banana = 1, cherry = 2 };

Perl

Interpeter: Perl

 enum fruits { apple, banana, cherry };
 enum fruits { apple = 0, banana = 1, cherry = 2 };

PHP

 enum fruits { apple, banana, cherry };
 enum fruits { apple = 0, banana = 1, cherry = 2 };

Python

Interpeter: Python 2.3, 2.4, 2.5