Originally Posted by
ncode
I was studying my book and suddenly there are something called enumeration pop up. What's that means?
Code:
enum Status{ CONTINUE, WON, LOST};
Enums are often used to when you have something (i.e. a state) that can be defined by a number, but instead of using the number itself you want a more descriptive expression. One example is a state machine, consider one that has the states on, off and idle, represented by the numbers 1, 2 and 3. Instead of doing this in your code:
Code:
int state = 1;
switch(state) {
case 1:
/* In state on */
break;
case 2:
/* In state off */
break;
case 3:
/* In state idle */
break;
}
You can be more clear, if you use an enum to describe the states:
Code:
enum STATE {
ON = 1,
OFF = 2,
IDLE = 3
};
enum STATE state = ON;
switch(state) {
case ON:
/* In state on */
break;
case OFF:
/* In state off */
break;
case IDLE:
/* In state idle */
break;
}