-2

Is there a term or some short wording to refer to an expression in the "first" line of the control flow statement?

func() {
  if (a == b) {
    var = 1 + 1
    return True
  } else {
    var = 5 + 5
    return False
  }
}
if ((a == b)
 && (c == d)) {
  ...
}

In the first example, the term/wording should "match" a == b, True, and False. It should not match 1 + 1 and 5 + 5.

In the second example, it should match (a == b) && (c == d).

I used to use "control flow statement expression", but I do not think this term is accurate.

john c. j.
  • 491
  • 3
  • 9
  • 1
    boolean expression? – George Barwood Jun 27 '20 at 10:05
  • @GeorgeBarwood In such a case, it will match `True` in `var = True`, right? It should not do so. – john c. j. Jun 27 '20 at 10:15
  • 1
    Are you referring perhaps to the *condition* or the *test*? – Steve Jun 27 '20 at 11:23
  • @Steve The terms "condition" and "conditional expression" don't match `True` and `False` in `return True` and `return False`. – john c. j. Jun 27 '20 at 11:31
  • 1
    Just thinking about more complex cases as well. The header of the switch statement would probably be formally called the *comparand* (and the matching blocks the *cases*). A for loop is typically considered to be a complex compound statement - individually you could refer to the initialiser, test, and stepping - but with all three as a unit you might call it the *control section* or the *controls* (as in, "the control section of the for loop" or "the controls have been modified on the for loop"). – Steve Jun 27 '20 at 11:34
  • 1
    I'm not quite sure what you mean by "matching true and false". Those statements do not fall in the "first line of the control flow statement", which is the element about which you asked for names/wording. Is there any significance to the fact that these statements all *evaluate* to a boolean type? – Steve Jun 27 '20 at 11:38
  • @Steve *I'm not quite sure what you mean by "matching true and false". Those statements do not fall in the "first line of the control flow statement"* - As I see it, a) `return True` and `return False` are control flow statements, b) `True` and `False` are literal expressions, c) hence, the term should match `True` in `return True` as well as `a == b` in `if (a == b)`. ¶ I like your "control section" idea, thanks a lot. But what you think about "a control flow statement header expression", is it correct to use such a wording when we talk about loops? – john c. j. Jun 27 '20 at 12:00
  • "are literal expressions" ooops, I mean Boolean expression. – john c. j. Jun 27 '20 at 12:06
  • How about `return a == b;` ? We don't need to use conditional control flow to return a boolean. – Erik Eidt Jun 27 '20 at 14:40
  • 1
    I'm still not really understanding what you mean by "hence, the term should match True in return True". What exactly does it mean for this undiscovered term to "match true"? By "match", do you mean the term is *suitable to describe* an expression (or some element of a statement) which evaluates to true (or to false)? Or do you mean something else (since we have already ruled out "boolean expression")? (1/2) – Steve Jun 27 '20 at 20:09
  • As to a "control flow statement header expression", I can understand the meaning in context, but I don't find it evocative or felicitous (let alone snappy!). If you were describing the whole first line of any block, such as that which controls entry or repetition, then offhand I might describe it as the "block header". In an appropriate sentence it might be self-explanatory, but I'm not aware of an accepted term. (2/2) – Steve Jun 27 '20 at 20:24
  • @ErikEidt Thanks. Yes, it would be better to edit the example so it will return string literals, `return "Foo"` and `return "Bar"`. But I think it is better to keep it as is because of the discussion in comments, to avoid further confusion. – john c. j. Jun 27 '20 at 20:57
  • @Steve *"By 'match', do you mean the term is **suitable to describe** an expression (or some element of a statement) which evaluates to `true` (or to `false`)?"* Yes, this is what I mean. Sorry for the confusion! (I use the word "match" the same way as it's used when we talk about regular expressions. I hope this metaphor will not add new confusion!) – john c. j. Jun 27 '20 at 21:10
  • 1
    So what is wrong with "boolean expression"? You give the example earlier of assignment of a Boolean value to a variable ("var = True") which should fall outside the definition of the undiscovered term, but I'm not clear why this is a *fundamentally different* case or why the term must exclude this case. Certainly, in C, assignment to a variable is itself an expression that is capable of being evaluated (and which evaluates to the assigned value). Speculating, is it the fact that assignment has side effects (i.e. is functionally "impure")? – Steve Jun 27 '20 at 21:45

1 Answers1

1

I don't know of a single term which exactly match your criteria. Your criteria seem rather arbitrary anyway since the condition in an if statement affect control flow, while a return value does not affect control flow (even though the return statement does).

Also the "first line" criteria is a bit arbitrary. For example multiple languages have both

while (condition) statement;

and

do statement while (condition);

Clearly the condition have the same function in both examples despite the position.

In short, the term you are looking for would not be very useful if it existed.

JacquesB
  • 57,310
  • 21
  • 127
  • 176