Selection CASE Statement Damian Gordon Selection As well
- Slides: 13
Selection: CASE Statement Damian Gordon
Selection • As well as the IF Statement, another form of SELECTION is the CASE statement.
CASE Statement • If we had a multi-choice question:
CASE Statement • If we had a multi-choice question:
CASE Statement Read Answer; IF (Answer = ‘A’) THEN Print “That is incorrect”; ELSE IF (Answer = ‘B’) THEN Print “That is incorrect”; ELSE IF (Answer = ‘C’) THEN Print “That is Correct”; ELSE IF (Answer = ‘D’) THEN Print “That is incorrect”; ELSE Print “Bad Option”; END IF;
CASE Statement PROGRAM Multi. Choice. Question: Read Answer; IF (Answer = ‘A’) THEN Print “That is incorrect”; ELSE IF (Answer = ‘B’) THEN Print “That is incorrect”; ELSE IF (Answer = ‘C’) THEN Print “That is Correct”; ELSE IF (Answer = ‘D’) THEN Print “That is incorrect”; ELSE Print “Bad Option”; ENDIF; END.
CASE Statement Read Answer; CASE OF Answer ‘A’ : Print ‘B’ : Print ‘C’ : Print ‘D’ : Print OTHER: Print ENDCASE; “That is incorrect”; “That is Correct”; “That is incorrect”; “Bad Option”;
CASE Statement PROGRAM Multi. Choice. Question: Read Answer; CASE OF Answer ‘A’ : Print “That is incorrect”; ‘B’ : Print “That is incorrect”; ‘C’ : Print “That is Correct”; ‘D’ : Print “That is incorrect”; OTHER: Print “Bad Option”; ENDCASE; END.
CASE Statement • Or, in general: CASE OF Value Option 1: <Statements>; Option 2: <Statements>; Option 3: <Statements>; Option 4: <Statements>; OTHER : <Statements>; ENDCASE;
START Read in A Option 1 Yes Print “Option 1” No Option 2 Yes Print “Option 2” No OTHER No END Yes Print “OTHER”
CASE Statement Read Result; CASE OF Result => 70 : Print “You got a first”; Result => 60 : Print “You got a 2. 1”; Result => 50 : Print “You got a 2. 2”; Result => 40 : Print “You got a 3”; OTHER : Print “Dude, you failed”; ENDCASE;
CASE Statement PROGRAM Get. Grade: Read Result; CASE OF Result => 70 : Print “You got a first”; Result => 60 : Print “You got a 2. 1”; Result => 50 : Print “You got a 2. 2”; Result => 40 : Print “You got a 3”; OTHER : Print “Dude, you failed”; ENDCASE; END.
etc.
- Damian gordon
- Filetype: pdf
- Damian gordon
- Best worst and average case
- Definition of safe and wholesome water
- Eat well stay well
- Eat well live well with spinal cord injury
- The part can never be well unless the whole is well
- Well defined set
- "to be happy is to live well and to do well."
- How to write a conclusio
- Damian sturzaker
- Padre damian de veuster 2215 vitacura
- Padre damian de veuster 2215 vitacura