Case Statements

Question: What are the advatages and disadvantages of case statement in pseudocode?
anonymous

Answer: There are no disadvantages.

The main advantage is that it translates directly into code in the 90%+ of languages that have some sort of case statement built in.

eg the following might be what you end up with in Javascript if you use a case statement in your pseudocode (if you use if statements you end up with far less efficient code):

switch(finished) {
  case 1: alert('first'); break;
  case 2: alert('second'); break;
  case 3: alert('third'); break;
  default: alert('did not place');
}

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate