4. Some people who do not mess with the IF statement, I like to use the "if" statement, as follows:
IF (a == 0)
{
A ;
Return (a);
}
IF (a == 1)
{
A = 5;
Return (a);
}
IF (a == 2)
{
A = 10;
Return (a);
}
IF (a == 3)
{
A = 20;
Return (a);
}
IF (a == 4)
Exit (1);
Is there a better way than this? ELSE IF statement? Not. A good way is to write a simple program with the "Switch-Case" statement:
Switch (a)
{
Case 0: A ;
Return (a);
Case 1: A = 5;
Return (a);
Case 2: A = 10;
Return (a);
Case 3: A = 20;
Return (a);
DEFAULT: EXIT (1);
}
If no value consistent with A, the job defined in default is executed, and the above example is to perform the end.