Expression Versus Statement

前端 未结 21 1741
别那么骄傲
别那么骄傲 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:28

    Statements are grammatically complete sentences. Expressions are not. For example

    x = 5
    

    reads as "x gets 5." This is a complete sentence. The code

    (x + 5)/9.0
    

    reads, "x plus 5 all divided by 9.0." This is not a complete sentence. The statement

    while k < 10: 
        print k
        k += 1
    

    is a complete sentence. Notice that the loop header is not; "while k < 10," is a subordinating clause.

提交回复
热议问题