0

In some programming languages, such as Pascal, there is a case statement written like case something of, like case name of or case place of, followed by a set of alternatives. This expression, case noun of, is unfamiliar to me, I've never heard or read it before, even after looking for it in dictionaries.

Is it correct in English? If so, can you provide an example, like a quote of a book that uses it, or a dictionary that lists it. If not, is it an abbreviation of something else, like in case of something is, or just something that the programming language designers invented with no natural way of reading it?

EDIT: I understand what the case statement does in programming languages. I just don't understand where that syntax comes from.

2 Answers 2

1

It doesn't really match anything in everyday English, though it is similar to the way "case" is used in set phrases like "in any case", "case by case", "as the case may be", etc.

It does match a standard way to organize mathematical proofs where there are several mutually exclusive situations which need to be considered separately. For example a math proof might be written something like this:

"There are three cases to consider.

  1. If x > 0, then ...
  2. If x = 0, then ...
  3. If x < 0, then ..."

The similarity to the case statement in Pascal, or the switch statement in C, should be clear.

1
  • Would you say that the case something of syntax is potentially confusing for native English speakers too?
    – Hawkings
    Commented Jan 7, 2019 at 1:12
0

The switch/case statements in languages like C and Java, do have a basis in English, but like most code, it's generalised and simplified.

English: "In case of fire, use the marked exits. Do not use lifts."

Java:

switch (condition) {
  case BUILDING_ON_FIRE: use(exit);
  default:               use(lift);
}
2
  • Can you explain what simplification is being performed? Why is of after the noun?
    – Hawkings
    Commented Jan 7, 2019 at 1:15
  • Of is used in many expressions like that in English: This is an example of using it. There is a risk of losing money. I am sure of it. Commented Jan 7, 2019 at 1:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .