中国特工组织叫什么| 11.2是什么星座| 爬虫什么意思| 吃维生素b1有什么好处和副作用| 豌豆的什么不能吃| 老年人脚肿挂什么科| 知了代表什么生肖| 南瓜和什么不能一起吃| 萝卜什么时候种| 什么样的防晒霜比较好| 非农业户口是什么意思| 宋威龙什么星座| 激光脱毛有什么副作用| 一年一片避孕药叫什么| 儿童感冒吃什么药| 同甘共苦什么意思| kj什么意思| 手指长痣代表什么| 牙龈肿是什么原因| 八方来财是什么生肖| 保护嗓子长期喝什么茶| 柠檬配什么泡水喝最好| 便秘吃什么最快排便| 手麻脚麻是什么原因| 白蛋白下降是什么原因| 小龙虾什么季节| 球镜是什么意思| 继女是什么意思| 蛇脱皮在家有什么预兆| 98年的属什么| 小儿安现在叫什么名| 月经前长痘痘是什么原因| 知了猴是什么| 病灶什么意思| 尿多是什么问题| aca是什么意思| 生理盐水有什么作用| 双手麻是什么原因| 5月是什么月| 男性阴囊瘙痒是什么病| 梦见女婴儿是什么意思| 五六点是什么时辰| 低压高吃什么药最有效| 胰岛素是什么意思| 卧推60公斤什么水平| package什么意思| 小腹变大是什么原因| 阴茎硬度不够吃什么药| 诺如病毒是什么症状| 梦见河水是什么意思| 刷墙的白色涂料叫什么| 为什么合欢树又叫鬼树| 夏天喝绿茶有什么好处| 嘴角烂了是什么原因| 毫无意义是什么意思| 天葬是什么| 头疼是什么病的前兆| 肝血管瘤是什么病| 迪士尼是什么意思| 怀孕什么时候能测出来| 电轴右偏是什么意思| 32周岁属什么生肖| 省政协主席什么级别| 微波炉蒸鸡蛋羹几分钟用什么火| 萎靡是什么意思| 5201314是什么意思| 百合花语是什么意思| 乌唇是什么原因| 仓鼠是什么动物| 备孕吃什么最容易怀孕| amy什么意思| 俄罗斯信奉什么教| 眼睛红是什么原因引起的| 皮毒清软膏有什么功效| 手突然抖动是什么原因| 996是什么意思| 甲状腺功能亢进症是什么病| fbi相当于中国的什么| 清热败火的败是什么意思| 韩国欧巴是什么意思| 老年人脚浮肿是什么原因| 手脚冰凉吃什么药| 梦见掉牙齿是什么意思| 做什么来钱快| 暴力倾向的人有什么表现| 避孕套和安全套有什么区别| 孩子贫血吃什么补血最快| 减肥去医院挂什么科| 什么是脊柱侧弯| 牙髓炎吃什么药最有效| 逆流而上是什么意思| 巾帼不让须眉是什么意思| 类风湿为什么反复发烧| 什么的围巾| 什么是孽缘| 梦到羊是什么意思| 中尉是什么级别| 窦性心律过缓什么意思| 孕中期同房要注意什么| 血管炎不能吃什么食物| pr是什么职位| 生鱼是什么鱼| 什么样的伤口需要打破伤风| 眼皮跳是什么原因| 六月十三日是什么日子| 霉菌性阴道炎什么症状| 咽喉疱疹是什么症状| 鸡炖什么好吃又有营养| 甲状腺是什么意思| 健忘症是什么意思| 芒果是什么意思| 老子是什么意思| 糖醋排骨用什么醋好吃| 上环要做什么检查| 尿路感染吃什么药效果好| 经常流鼻血是什么病的前兆| 黑裙子配什么鞋子| 右手指发麻是什么原因| 幽门螺杆菌是什么意思| 吃什么不长肉| 阶段是什么意思| 甘油三酯高吃什么药| 脸上长毛什么原因| ckd是什么病| 什么木质手串最好| 螺子黛是什么| 椰浆和椰汁有什么区别| 什么时候怀孕几率高| 金牛女跟什么星座最配| 养殖什么赚钱| 葡萄籽有什么功效| 清水是什么意思| 皮肤发红发烫是什么原因| paw是什么意思| 苹果充电口叫什么| 洗发水和洗发露有什么区别| 慎独什么意思| x光是检查什么的| 海竹是什么| 养狗养不活是什么兆头| 小暑是什么时候| 岂是什么意思| 什么叫精神病| 梅子色是什么颜色| 肉芽肿是什么病| 突然尿频是什么原因| 硒片不适合什么人吃| 5年存活率是什么意思| 被蜱虫咬了有什么症状| 喧宾夺主什么意思| 小螃蟹吃什么食物| 硝苯地平是什么药| 正方形纸能折什么| 口角炎涂什么药膏| 女人眉毛稀少代表什么| 海狗是什么| 月经期间肚子疼是什么原因| 吃什么长内膜最快最有效| 王属什么五行| 白带是什么| 妈妈的奶奶应该叫什么| 带状疱疹是什么引起的| 什么是普拉提| 日什么月什么| 李子吃了有什么好处| 秋千为什么叫秋千| 朱砂有什么功效| 甲状腺球蛋白抗体高是什么原因| 大水牛是什么意思| 醋酸氯已定是什么药| 579是什么意思| 荷花象征什么| 龙的本命佛是什么佛| 智力是什么意思| 梦见买狗是什么意思| 什么是再生障碍性贫血| 人间四月芳菲尽的尽是什么意思| 梦到跟人吵架是什么意思| 颈椎病用什么枕头最好| 舒张压是什么意思| 中暑了喝什么| 什么是基础代谢| 为什么空腹喝牛奶会拉肚子| 一路长虹什么意思| 喝中药不能吃什么东西| 藏茶属于什么茶| 氧氟沙星和诺氟沙星有什么区别| 1月16日是什么星座| 吃什么利尿| 什么牌子的洗面奶好用| 孕妇羊水少吃什么补的快| 化疗是什么意思| 泰能是什么药| 国师是什么意思| 喝豆腐脑有什么好处和坏处| 维生素b3又叫什么| 黑色的蜂是什么蜂| 藿香正气水什么味| 子宫出血什么原因| 口腔溃疡挂什么科| 结节病变是什么意思| 睛可以组什么词| 夏天煲鸡汤放什么材料| 沉稳是什么意思| 超声是什么检查| 专柜是什么意思| 侯赛因是什么意思| 丝瓜络是什么| 处方药是什么标志| 杏仁和什么不能一起吃| 外感病是什么意思| 踩奶是什么意思| 疯马皮是什么皮| 坐怀不乱柳下惠什么意思| 什么叫醪糟| 6月26号是什么日子| 2月什么星座| 什么叫阴虱| 刺梨是什么| 视功能是什么| 多吃玉米有什么好处和坏处| 李时珍的皮是什么意思| 河东狮吼什么意思| 御木本是什么档次| 为什么怀不上孩子| 苹果枸杞红枣煮水喝有什么功效| 黄油可以用什么代替| 急性肠胃炎打什么点滴| 枕头太低有什么影响| fmc是什么意思| 硒片不适合什么人吃| 剁椒鱼头是什么菜系| 体寒的女人吃什么能调理好身体| 张伦硕为什么娶钟丽缇| 海底轮是什么意思| 脖子下面是什么部位| 没有什么会永垂不朽| 天线宝宝都叫什么名字| 丙肝有什么症状表现| 什么牙什么嘴| 钟乳石是什么| 睾丸胀痛什么原因| 青霉素过敏吃什么消炎药| 吃什么保养子宫和卵巢| 梦见弟媳妇是什么预兆| 梦到手机丢了什么预兆| 左眼皮上有痣代表什么| 山梨酸是什么| 梨状肌综合症吃什么药| 八月是什么星座| 黑猫警长是什么猫| 一什么种子| 二便是什么意思| 甲醛是什么| 做梦梦到地震预示着什么| 秀才相当于什么学历| 一岁宝宝口臭是什么原因引起的| 梦见家里水管漏水是什么意思| 结肠多发憩室是什么意思| 输卵管囊肿是什么原因引起的| 防晒隔离什么牌子好| 怀孕初期能吃什么不能吃什么| 双鱼座和什么座最配| 劳模是什么意思| 百度

三星借OLED版iPhone大赚:显示芯片创收4亿美元

(Redirected from Statement (programming))
百度 道路是一个城市的命脉,它的兴建和变化,都折射出一个城市的发展历程,伴随着海南建省办经济特区的步伐,东方,这座海南西海岸边的滨海小城如浴春风,发生了翻天覆地的变化,交通就是这变化中最大的亮点之一。

In computer programming, a statement is a syntactic unit of an imperative programming language that expresses some action to be carried out.[1] A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components (e.g. expressions).

Many programming languages (e.g. Ada, Algol 60, C, Java, Pascal) make a distinction between statements and definitions/declarations. A definition or declaration specifies the data on which a program is to operate, while a statement specifies the actions to be taken with that data.

Statements which cannot contain other statements are simple; those which can contain other statements are compound.[2]

The appearance of a statement (and indeed a program) is determined by its syntax or grammar. The meaning of a statement is determined by its semantics.

Simple statements

edit

Simple statements are complete in themselves; these include assignments, subroutine calls, and a few statements which may significantly affect the program flow of control (e.g. goto, return, stop/halt). In some languages, input and output, assertions, and exits are handled by special statements, while other languages use calls to predefined subroutines.

  • assignment
    • Fortran: variable = expression
    • Pascal, Algol 60, Ada: variable := expression;
    • C, C#, C++, PHP, Java: variable = expression;
  • call
    • Fortran: CALL subroutine name(parameters)
    • C, C++, Java, PHP, Pascal, Ada: subroutine name(parameters);
  • assertion
    • C, C++, PHP: assert(relational expression);
    • Java: assert relational expression;
  • goto
    • Fortran: GOTO numbered-label
    • Algol 60: goto label;
    • C, C++, PHP, Pascal: goto label;
  • return
    • Fortran: RETURN value
    • C, C++, Java, PHP: return value;
  • stop/halt/exit
    • Fortran: STOP number
    • C, C++: exit(expression)
    • PHP: exit number;

Compound statements

edit

Compound statements may contain (sequences of) statements, nestable to any reasonable depth, and generally involve tests to decide whether or not to obey or repeat these contained statements.

Notation for the following examples:
  • <statement> is any single statement (could be simple or compound).
  • <sequence> is any sequence of zero or more <statements>
Some programming languages provide a general way of grouping statements together, so that any single <statement> can be replaced by a group:
  • Algol 60: begin <sequence> end
  • Pascal: begin <sequence> end
  • C, PHP, Java: { <sequence> }
Other programming languages have a different special terminator on each kind of compound statement, so that one or more statements are automatically treated as a group:
  • Ada: if test then <sequence> end if;

Many compound statements are loop commands or choice commands. In theory only one of each of these types of commands is required. In practice there are various special cases which occur quite often; these may make a program easier to understand, may make programming easier, and can often be implemented much more efficiently. There are many subtleties not mentioned here; see the linked articles for details.

  • count-controlled loop:
    • Algol 60: for index := 1 step 1 until limit do <statement> ;
    • Pascal: for index := 1 to limit do <statement> ;
    • C, Java: for ( index = 1; index <= limit; index += 1) <statement> ;
    • Ada: for index in 1..limit loop <sequence> end loop
    • Fortran 90:
      DO index = 1,limit
          <sequence>
      END DO
      
  • condition-controlled loop with test at start of loop:
    • Algol 60: for index := expression while test do <statement> ;
    • Pascal: while test do <statement> ;
    • C, Java: while (test) <statement> ;
    • Ada: while test loop <sequence> end loop
    • Fortran 90:
      DO WHILE (test)
          <sequence>
      END DO
      
  • condition-controlled loop with test at end of loop:
    • Pascal: repeat <sequence> until test; { note reversed test }
    • C, Java: do { <sequence> } while (test) ;
    • Ada: loop <sequence> exit when test; end loop;
  • condition-controlled loop with test in the middle of the loop:
    • C: do { <sequence> if (test) break; <sequence> } while (true) ;
    • Ada: loop <sequence> exit when test; <sequence> end loop;
  • if-statement simple situation:
    • Algol 60:if test then <unconditional statement> ;
    • Pascal: if test then <statement> ;
    • C, Java: if (test) <statement> ;
    • Ada: if test then <sequence> end if;
    • Fortran 77+:
      IF (test) THEN
          <sequence>
      END IF
      
  • if-statement two-way choice:
    • Algol 60: if test then <unconditional statement> else <statement> ;
    • Pascal: if test then <statement> else <statement> ;
    • C, Java: if (test) <statement> else <statement> ;
    • Ada: if test then <sequence> else <sequence> end if;
    • Fortran 77+:
      IF (test) THEN
          <sequence>
      ELSE
          <sequence>
      END IF
      
  • case/switch statement multi-way choice:
    • Pascal: case c of 'a': alert(); 'q': quit(); end;
    • Ada: case c is when 'a' => alert(); when 'q' => quit(); end case;
    • C, Java: switch (c) { case 'a': alert(); break; case 'q': quit(); break; }
  • Exception handling:
    • Ada: begin protected code except when exception specification => exception handler
    • Java: try { protected code } catch (exception specification) { exception handler } finally { cleanup }
    • Python: try: protected code except exception specification: exception handler else: no exceptions finally: cleanup

Syntax

edit

Apart from assignments and subroutine calls, most languages start each statement with a special word (e.g. goto, if, while, etc.) as shown in the above examples. Various methods have been used to describe the form of statements in different languages; the more formal methods tend to be more precise:

  • Algol 60 used Backus–Naur form (BNF) which set a new level for language grammar specification.[3]
  • Up until Fortran 77, the language was described in English prose with examples,[4] From Fortran 90 onwards, the language was described using a variant of BNF.[5]
  • Cobol used a two-dimensional metalanguage.[6]
  • Pascal used both syntax diagrams and equivalent BNF.[7]

BNF uses recursion to express repetition, so various extensions have been proposed to allow direct indication of repetition.

Statements and keywords

edit

Some programming language grammars reserve keywords or mark them specially, and do not allow them to be used as identifiers. This often leads to grammars which are easier to parse, requiring less lookahead.

No distinguished keywords

edit

Fortran and PL/1 do not have reserved keywords, allowing statements like:

  • in PL/1:
    • IF IF = THEN THEN ... (the second IF and the first THEN are variables).
  • in Fortran:
    • IF (A) X = 10... conditional statement (with other variants)
    • IF (A) = 2 assignment to a subscripted variable named IF
As spaces were optional up to Fortran 95, a typo could completely change the meaning of a statement:
  • DO 10 I = 1,5 start of a loop with I running from 1 to 5
  • DO 10 I = 1.5 assignment of the value 1.5 to the variable DO10I

Flagged words

edit

In Algol 60 and Algol 68, special tokens were distinguished explicitly: for publication, in boldface e.g. begin; for programming, with some special marking, e.g., a flag ('begin), quotation marks ('begin'), or underlined (begin on the Elliott 503). This is called "stropping".

Tokens that are part of the language syntax thus do not conflict with programmer-defined names.

Reserved keywords

edit

Certain names are reserved as part of the programming language and can not be used as programmer-defined names. The majority of the most popular programming languages use reserved keywords. Early examples include FLOW-MATIC (1953) and COBOL (1959). Since 1970 other examples include Ada, C, C++, Java, and Pascal. The number of reserved words depends on the language: C has about 30 while COBOL has about 400.

Semantics

edit

Semantics is concerned with the meaning of a program. The standards documents for many programming languages use BNF or some equivalent to express the syntax/grammar in a fairly formal and precise way, but the semantics/meaning of the program is generally described using examples and English prose. This can result in ambiguity.[8] In some language descriptions the meaning of compound statements is defined by the use of 'simpler' constructions, e.g. a while loop can be defined by a combination of tests, jumps, and labels, using if and goto.

The semantics article describes several mathematical/logical formalisms which have been used to specify semantics in a precise way; these are generally more complicated than BNF, and no single approach is generally accepted as the way to go. Some approaches effectively define an interpreter for the language, some use formal logic to reason about a program, some attach affixes to syntactic entities to ensure consistency, etc.

Expressions

edit

A distinction is often made between statements, which are executed, and expressions, which are evaluated. Expressions always evaluate to a value, which statements do not. However, expressions are often used as part of a larger statement.

In most programming languages, a statement can consist of little more than an expression, usually by following the expression with a statement terminator (semicolon). In such a case, while the expression evaluates to a value, the complete statement does not (the expression's value is discarded). For instance, in C, C++, C#, and many similar languages, x = y + 1 is an expression that will set x to the value of y plus one, and the whole expression itself will evaluate to the same value that x is set to. However, x = y + 1; (note the semicolon at the end) is a statement that will still set x to the value of y plus one because the expression within the statement is still evaluated, but the result of the expression is discarded, and the statement itself does not evaluate to any value.[9]

Expressions can also be contained within other expressions. For instance, the expression x = y + 1 contains the expression y + 1, which in turn contains the values y and 1, which are also technically expressions.

Although the previous examples show assignment expressions, some languages do not implement assignment as an expression, but rather as a statement. A notable example of this is Python, where = is not an operator, but rather just a separator in the assignment statement. Although Python allows multiple assignments as each assignment were an expression, this is simply a special case of the assignment statement built into the language grammar rather than a true expression.[10]

Extensibility

edit

Most languages have a fixed set of statements defined by the language, but there have been experiments with extensible languages that allow the programmer to define new statements.

See also

edit

References

edit
  1. ^ "statement". webopedia. September 1996. Retrieved 2025-08-05.
  2. ^ Backus, J.W.; Bauer, F.L.; Green, J.; Katz, C.; McCarthy, J.; Naur, P.; Perlis, A.J.; Rutishauser, H.; Samuelson, K.; Vauquois, B.; Wegstein, J.H.; van Wijngaarden, A.; Woodger, M. Naur, Peter (ed.). "Revised Report on the Algorithmic Language Algol 60". mass:werk. Section "4.1". Retrieved January 23, 2021.
  3. ^ Backus, J.W.; Bauer, F.L.; Green, J.; Katz, C.; McCarthy, J.; Naur, P.; Perlis, A.J.; Rutishauser, H.; Samuelson, K.; Vauquois, B.; Wegstein, J.H.; van Wijngaarden, A.; Woodger, M. Naur, Peter (ed.). "Revised Report on the Algorithmic Language Algol 60". mass:werk. Section "1.1". Retrieved January 23, 2021.
  4. ^ "FORTRAN" (PDF). United States of America Standards Institute. 1966. Retrieved February 19, 2021 – via WG5 Fortran Standards.
  5. ^ "Working draft J3/04-007" (PDF). J3 Fortran. May 10, 2004. Retrieved February 19, 2021.
  6. ^ "ASCII COBOL Programming Reference Manual" (PDF). unisys. June 2010. Retrieved January 23, 2021.
  7. ^ Jensen, Kathleen; Wirth, Niklaus (1974). Goos, G.; Hartmanis, J. (eds.). "PASCAL User Manual and Report" (PDF). Lecture Notes in Computer Science. Appendix D. Retrieved February 19, 2021.
  8. ^ Knuth, D. E. (Jul 1967). "The Remaining Trouble Spots in Algol 60" (PDF). The ALGOL Family. Retrieved February 24, 2021.
  9. ^ "ISO/IEC 9899:1999 (E)" (PDF). ISO/IEC. Archived (PDF) from the original on Feb 7, 2024.
  10. ^ "7. Simple statements". Python 3.10.8 documentation.
edit
罗非鱼是什么鱼 外阴苔癣是一种什么病 台湾什么时候收复 前列腺炎什么症状 抑郁是什么意思
吃什么增强抵抗力和免疫力 吃了龙虾后不能吃什么 点睛之笔是什么意思 小针刀是什么手术 梦见芹菜是什么意思
梦到棺材什么意思 rag是什么 什么孩子命里有文曲星 缩量十字星意味着什么 为什么胃有灼热感
pde是什么意思 碗莲什么时候开花 喉咙发甜是什么原因 fion属于什么档次的包 去痘印用什么药膏
偷袭是什么意思hcv7jop5ns6r.cn 香港脚是什么症状图片hcv8jop7ns5r.cn 娇嫩的意思是什么hcv8jop0ns5r.cn 社会科学院是干什么的hcv8jop7ns1r.cn 红薯的别名叫什么hcv7jop6ns3r.cn
肿瘤cr是什么意思hcv7jop4ns7r.cn 月经期间不能吃什么hcv9jop3ns6r.cn 免费查五行缺什么hcv8jop7ns1r.cn 弥是什么意思hcv8jop8ns6r.cn 中医是什么hcv9jop1ns7r.cn
疤痕体质是什么youbangsi.com 九月是什么星座hcv9jop6ns3r.cn 双向转诊是什么意思mmeoe.com 山药炒什么好吃qingzhougame.com 鮰鱼是什么鱼xscnpatent.com
猫离家出走预示着什么hcv9jop6ns4r.cn 女人怀孕的最佳时间是什么时间hcv8jop4ns9r.cn 罕见是什么意思hcv7jop9ns3r.cn 左肾囊性灶是什么意思hcv9jop5ns1r.cn 三合一是什么意思hcv8jop3ns7r.cn
百度