Expression Versus Statement

前端 未结 21 1969
别那么骄傲
别那么骄傲 2020-11-22 11:54

I\'m asking with regards to c#, but I assume its the same in most other languages.

Does anyone have a good definition of expressions and statements

21条回答
  •  天涯浪人
    2020-11-22 12:20

    Statements -> Instructions to follow sequentially
    Expressions -> Evaluation that returns a value

    Statements are basically like steps, or instructions in an algorithm, the result of the execution of a statement is the actualization of the instruction pointer (so-called in assembler)

    Expressions do not imply and execution order at first sight, their purpose is to evaluate and return a value. In the imperative programming languages the evaluation of an expression has an order, but it is just because of the imperative model, but it is not their essence.

    Examples of Statements:

    for
    goto
    return
    if
    

    (all of them imply the advance of the line (statement) of execution to another line)

    Example of expressions:

    2+2
    

    (it doesn't imply the idea of execution, but of the evaluation)

提交回复
热议问题