Π§Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ statement Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ

ΠžΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΈ, выраТСния ΠΈ инструкции [operators, expressions and statements]

ΠžΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΈ [operators]

Для Π±ΠΎΠ»Π΅Π΅ Π΄Π΅Ρ‚Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ рассмотрСния ΠΈ ΠΎΡ…Π²Π°Ρ‚Π° ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΉ, Π½Π΅ рассмотрСнных здСсь, см. the Mozilla Developer Network (MDN)’s β€œΠ’Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΡ ΠΈ опСраторы”.

ВыраТСния [expressions]

ВыраТСния ΠΌΠΎΠΆΠ΅Ρ‚ находится Π²Π΅Π·Π΄Π΅, Π³Π΄Π΅ Javascript ΠΎΠΆΠΈΠ΄Π°Π΅Ρ‚ ΠΊΠ°ΠΊΠΎΠ΅-Ρ‚ΠΎ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅. НапримСр, Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π²Ρ‹ΡΡ‚ΡƒΠΏΠ°Ρ‚ΡŒ Π² качСствС ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π° Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ.

Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΠΈ [statements]

ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ β€” это всСго лишь Π½Π°Π±ΠΎΡ€ ΡΡ‚ΠΎΠ»ΡŒΠΊΠΈΡ… инструкций, сколько Π½ΡƒΠΆΠ½ΠΎ для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ всС шаги, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹Π΅ для выполнСния Ρ†Π΅Π»ΠΈ вашСй ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹.

НапримСр, Π²ΠΎΡ‚ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ конструкции Π² JavaScript, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΡΠ²Π»ΡΡŽΡ‚ΡΡ инструкциями:

Для Π±ΠΎΠ»Π΅Π΅ Π΄Π΅Ρ‚Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ рассмотрСния ΠΈ ΠΎΡ…Π²Π°Ρ‚Π° ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΉ, Π½Π΅ рассмотрСнных здСсь, см. the Mozilla Developer Network (MDN)’s β€œΠ˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΠΈβ€.

Если Π²Π·ΡΡ‚ΡŒ Ρ‚ΠΎΡ‚ ΠΆΠ΅ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΈΠ· части Π²Ρ‹ΡˆΠ΅, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΌΡ‹ Ρ€Π°Π·Π±ΠΈΠ»ΠΈ Π½Π° выраТСния

Π’ JavaScript инструкции Π½Π΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Ρ‚Π°ΠΌ, Π³Π΄Π΅ оТидаСтся Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅. ΠŸΠΎΡΡ‚ΠΎΠΌΡƒ ΠΎΠ½ΠΈ Π½Π΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² качСствС Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ΠΎΠ² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ, ΠΏΡ€Π°Π²ΠΎΠΉ части присваиваний, Π² качСствС ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΉ ΠΈΠ»ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Ρ… Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ.

ΠŸΠ΅Ρ€Π΅Π΄Π°Ρ‡Π° Π² ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ инструкции if Π²Ρ‹Π·Π²Π°Π»ΠΎ ΡΠΈΠ½Ρ‚Π°ΠΊΡΠΈΡ‡Π΅ΡΠΊΡƒΡŽ ΠΎΡˆΠΈΠ±ΠΊΡƒ.

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: АнглийскоС слово operator, ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π΅ Ρ‚Π΅Ρ€ΠΌΠΈΠ½Ρƒ «опСрация», ΠΈΠ½ΠΎΠ³Π΄Π° ΠΎΡˆΠΈΠ±ΠΎΡ‡Π½ΠΎ пСрСводят ΠΊΠ°ΠΊ Β«ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Β». На самом Π΄Π΅Π»Π΅ (ΠΏΠΎ историчСским ΠΏΡ€ΠΈΡ‡ΠΈΠ½Π°ΠΌ) русский Ρ‚Π΅Ρ€ΠΌΠΈΠ½ Β«ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Β» (ΠΊΠΎΠ³Π΄Π° ΠΏΠΎΠ΄Ρ€Π°Π·ΡƒΠΌΠ΅Π²Π°Π΅Ρ‚ ΠΏΠΎΠ΄ собой ΠΊΠ°ΠΊΡƒΡŽ-Π»ΠΈΠ±ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ) ΠΎΠ±ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ Ρ‚ΠΎ ΠΆΠ΅, Ρ‡Ρ‚ΠΎ ΠΈ «инструкция», ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΉ соотвСтствуСт английскоС statement.

Π€ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½Ρ‹Π΅ выраТСния [function expression]

Π Π°Π½Π΅Π΅, Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ изучСния Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ, Π³ΠΎΠ²ΠΎΡ€ΠΈΠ»ΠΎΡΡŒ, Ρ‡Ρ‚ΠΎ функция являСтся ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠΌ, с ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ ΠΌΠΎΠΆΠ½ΠΎ ΠΌΠ°Π½ΠΈΠΏΡƒΠ»ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΊΠ°ΠΊ с Π»ΡŽΠ±Ρ‹ΠΌ Π΄Ρ€ΡƒΠ³ΠΈΠΌ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠΌ, ΠΈ опрСдСляСтся Π² ΠΊΠΎΠ΄Π΅ Ρ‚Π°ΠΊ

Π’Π°ΠΊΠΎΠ΅ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ называСтся β€œΠΎΠ±ΡŠΡΠ²Π»Π΅Π½ΠΈΠ΅ΠΌ функции” [function declaration] ΠΈ являСтся инструкциСй, которая создаёт Π½ΡƒΠΆΠ½ΡƒΡŽ Π½Π°ΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ.

Но функция ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΡ€Π΅Π΄ΡΡ‚Π°Π²Π»ΡΡ‚ΡŒ собой ΠΈ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ Π΅Ρ‰Π΅ называСтся β€œΡ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½Ρ‹ΠΌ выраТСниСм”. Π­Ρ‚ΠΎ происходит Π² случаС, Ссли ΠΌΡ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ Π΅Π΅ Ρ‚Π°ΠΌ, Π³Π΄Π΅ JavaScript ΠΎΠΆΠΈΠ΄Π°Π΅Ρ‚ ΠΊΠ°ΠΊΠΎΠ΅-Ρ‚ΠΎ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅.

ОсобСнно часто Π² качСствС выраТСния ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ Π°Π½ΠΎΠ½ΠΈΠΌΠ½Ρ‹Π΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΠΌΡ‹ ΠΌΠΎΠΆΠ΅ΠΌ ΠΏΡ€ΠΈΡΠ²ΠΎΠΈΡ‚ΡŒ Π΅Ρ‘ ΠΊΠ°ΠΊ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ

Π’Π°ΠΊ ΠΊΠ°ΠΊ Π² этой конструкции анонимная функция присваиваСтся ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΈ присваиваСт Π΅ΠΉ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅, Ρ‚ΠΎ эта функция являСтся Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ. Π”Π°Π»Π΅Π΅, ΠΌΡ‹ ΠΌΠΎΠΆΠ΅ΠΌ Π²Ρ‹Π·Π²Π°Ρ‚ΡŒ Π΅Ρ‘ ΠΊΠ°ΠΊ

Π’Ρ‹ΡΡ‚ΡƒΠΏΠ°Ρ‚ΡŒ Π² Ρ€ΠΎΠ»ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ выраТСния ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈ имСнованная функция, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Π½Π°ΠΌ Π½ΡƒΠΆΠ½ΠΎ имя Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²Ρ‹Π·Ρ‹Π²Π°Ρ‚ΡŒ Π΅Ρ‘ Π²Π½ΡƒΡ‚Ρ€ΠΈ самой сСбя (Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ Ρ€Π΅ΠΊΡƒΡ€ΡΠΈΡŽ)

Π”Π°Π»Π΅Π΅, этот ΠΌΠ΅Ρ‚ΠΎΠ΄ ΠΌΡ‹ смоТСм Π²Ρ‹Π·Π²Π°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

Вакая имСнованная функция, которая выступаСт Π² качСствС выраТСния, называСтся ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π½Π½Ρ‹ΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½Ρ‹ΠΌ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ.

Π•Ρ‰Π΅ ΠΎΠ΄Π½ΠΈΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ выраТСния являСтся функция, которая исполняСтся сразу ΠΆΠ΅ послС Ρ‚ΠΎΠ³ΠΎ, ΠΊΠ°ΠΊ ΠΎΠ½Π° Π±Ρ‹Π»Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π° (ΡΠ°ΠΌΠΎΠ²Ρ‹Π·Ρ‹Π²Π°ΡŽΡ‰ΠΈΠ΅ΡΠ΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ΅ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅)

Π‘Π°ΠΌ синтаксис Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ выраТСния практичСски повторяСт синтаксис объявлСния Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ, Ρ‚ΠΎΠ»ΡŒΠΊΠΎ имя Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½Ρ‹Ρ… выраТСниях ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΎΠΏΡƒΡ‰Π΅Π½ΠΎ для создания Π°Π½ΠΎΠ½ΠΈΠΌΠ½Ρ‹Ρ… Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ.

Π“Π»Π°Π²Π½Ρ‹ΠΌ ΠΎΡ‚Π»ΠΈΡ‡ΠΈΠ΅ΠΌ являСтся Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎ, ΠΊΠΎΠ³Π΄Π° ΠΌΡ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ, ΠΏΡƒΡΡ‚ΡŒ Π΄Π°ΠΆΠ΅ ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π½Π½ΡƒΡŽ Ρ‚Π°ΠΌ, Π³Π΄Π΅ JavaScript ΠΎΠΆΠΈΠ΄Π°Π΅Ρ‚ ΠΊΠ°ΠΊΠΎΠ΅-Ρ‚ΠΎ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ выраТСния, такая функция, соотвСтствСнно, называСтся Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½Ρ‹ΠΌ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ (ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅)

Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΈΠ»ΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ (Π°Π½Π³Π». statement ) β€” наимСньшая автономная Ρ‡Π°ΡΡ‚ΡŒ языка программирования; ΠΊΠΎΠΌΠ°Π½Π΄Π°. ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ прСдставляСт собой ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ инструкций.

МногиС языки (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Π‘ΠΈ) Ρ€Π°Π·Π»ΠΈΡ‡Π°ΡŽΡ‚ ΠΈΠ½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡŽ ΠΈ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅. Π Π°Π·Π»ΠΈΡ‡ΠΈΠ΅ Π² Ρ‚ΠΎΠΌ, Ρ‡Ρ‚ΠΎ инструкция исполняСт ΠΊΠΎΠ΄, Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ создаёт ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ (Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ ΠΌΠΎΠΆΠ½ΠΎ Ρ€Π°ΡΡΠΌΠ°Ρ‚Ρ€ΠΈΠ²Π°Ρ‚ΡŒ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΊΠ°ΠΊ ΠΈΠ½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡŽ присваивания).

НиТС ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Ρ‹ основныС ΠΎΠ±Ρ‰ΠΈΠ΅ инструкции ΠΈΠΌΠΏΠ΅Ρ€Π°Ρ‚ΠΈΠ²Π½Ρ‹Ρ… языков программирования.

Π‘ΠΌ. Ρ‚Π°ΠΊΠΆΠ΅

Π§Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ statement Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ Π§Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ statement Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ Π§Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ statement Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ Π§Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ statement Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ. Π€ΠΎΡ‚ΠΎ Π§Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ statement Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ

ПолСзноС

Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ‡Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ «ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ (ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅)» Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… словарях:

ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ β€” Π’ ВикисловарС Π΅ΡΡ‚ΡŒ ΡΡ‚Π°Ρ‚ΡŒΡ Β«ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Β» ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΠ·Π½Π°Ρ‡Π°Ρ‚ΡŒ: ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ (ΠΌΠ°Ρ‚Π΅ΠΌΠ°Ρ‚ΠΈΠΊΠ°) Ρ‚ΠΎ ΠΆΠ΅, Ρ‡Ρ‚ΠΎ матСматичСская функция; ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ (биология) ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ Π”ΠΠš, ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°ΡŽΡ‰Π°Ρ участиС Π² рСгуляции активности Π³Π΅Π½ΠΎΠ²; ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€β€¦ … ВикипСдия

ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ β€” 4.22 ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ (operator): Какой Π»ΠΈΠ±ΠΎ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚, ΠΎΡΡƒΡ‰Π΅ΡΡ‚Π²Π»ΡΡŽΡ‰ΠΈΠΉ Ρ€Π°Π±ΠΎΡ‚Ρƒ систСмы. ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅ 1 Роль ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° ΠΈ Ρ€ΠΎΠ»ΡŒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ ΠΌΠΎΠ³ΡƒΡ‚ Π²ΠΎΠ·Π»Π°Π³Π°Ρ‚ΡŒΡΡ ΠΎΠ΄Π½ΠΎΠ²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎ ΠΈΠ»ΠΈ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ Π½Π° ΠΎΠ΄Π½ΠΎ ΠΈ Ρ‚ΠΎ ΠΆΠ΅ Π»ΠΈΡ†ΠΎ ΠΈΠ»ΠΈ ΠΎΡ€Π³Π°Π½ΠΈΠ·Π°Ρ†ΠΈΡŽ. ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅ 2 Π’ контСкстС данного… … Π‘Π»ΠΎΠ²Π°Ρ€ΡŒ-справочник Ρ‚Π΅Ρ€ΠΌΠΈΠ½ΠΎΠ² Π½ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΠ²Π½ΠΎ-тСхничСской Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ

ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ β€” процСсс составлСния упорядочСнной ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ дСйствий (ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ (Π‘ΠΌ. ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°)) для Π­Π’Πœ; научная дисциплина, ΠΈΠ·ΡƒΡ‡Π°ΡŽΡ‰Π°Ρ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ для Π­Π’Πœ ΠΈ способы ΠΈΡ… составлСния, ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ ΠΈ ΡƒΠ»ΡƒΡ‡ΡˆΠ΅Π½ΠΈΡ. КаТдая Π­Π’Πœ являСтся Π°Π²Ρ‚ΠΎΠΌΠ°Ρ‚ΠΎΠΌ,… … Π‘ΠΎΠ»ΡŒΡˆΠ°Ρ совСтская энциклопСдия

ΠŸΠ ΠžΠ“Π ΠΠœΠœΠ˜Π ΠžΠ’ΠΠΠ˜Π• Π’Π•ΠžΠ Π•Π’Π˜Π§Π•Π‘ΠšΠžΠ• β€” матСматичСская дисциплина, ΠΈΠ·ΡƒΡ‡Π°ΡŽΡ‰Π°Ρ ΠΌΠ°Ρ‚Π΅ΠΌΠ°Ρ‚ΠΈΡ‡. абстракции ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌ, Ρ‚Ρ€Π°ΠΊΡ‚ΡƒΠ΅ΠΌΡ‹Ρ… ΠΊΠ°ΠΊ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρ‹, Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½Π½Ρ‹Π΅ Π½Π° Ρ„ΠΎΡ€ΠΌΠ°Π»ΡŒΠ½ΠΎΠΌ языкС, ΠΎΠ±Π»Π°Π΄Π°ΡŽΡ‰ΠΈΠ΅ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΎΠ½Π½ΠΎΠΉ ΠΈ Π»ΠΎΠ³ΠΈΡ‡. структурой ΠΈ ΠΏΠΎΠ΄Π»Π΅ΠΆΠ°Ρ‰ΠΈΠ΅ исполнСнию Π½Π° Π°Π²Ρ‚ΠΎΠΌΠ°Ρ‚ΠΈΡ‡. устройствах. П. Ρ‚.… … ΠœΠ°Ρ‚Π΅ΠΌΠ°Ρ‚ΠΈΡ‡Π΅ΡΠΊΠ°Ρ энциклопСдия

ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Π­Π­ оборудования ΠΈ/ΠΈΠ»ΠΈ Π­Π­ систСм β€” 3.17. ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Π­Π­ оборудования ΠΈ/ΠΈΠ»ΠΈ Π­Π­ систСм (operator of an EDM equipment and/or system): Π§Π΅Π»ΠΎΠ²Π΅ΠΊ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ осущСствляСт ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅, установку, Ρ€Π΅Π³ΡƒΠ»ΠΈΡ€ΠΎΠ²ΠΊΡƒ, наблюдСниС Π·Π° Ρ€Π°Π±ΠΎΡ‚ΠΎΠΉ, тСхничСскоС обслуТиваниС ΠΈ чистку станка. Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ: Π“ΠžΠ‘Π’ Π  … Π‘Π»ΠΎΠ²Π°Ρ€ΡŒ-справочник Ρ‚Π΅Ρ€ΠΌΠΈΠ½ΠΎΠ² Π½ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΠ²Π½ΠΎ-тСхничСской Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ

ГСнСтичСскоС ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ β€” Π’ искусствСнном ΠΈΠ½Ρ‚Π΅Π»Π»Π΅ΠΊΡ‚Π΅ гСнСтичСскоС ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ (Π“ΠŸ) автоматичСскоС созданиС ΠΈΠ»ΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ гСнСтичСских Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠΎΠ². Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ этой ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ»ΠΎΠ³ΠΈΠΈ Β«Π²Ρ‹Ρ€Π°Ρ‰ΠΈΠ²Π°ΡŽΡ‚ΡΡΒ» ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, всё Π»ΡƒΡ‡ΡˆΠ΅ ΠΈ Π»ΡƒΡ‡ΡˆΠ΅ (Π² соотвСтствии с опрСдСлСнной… … ВикипСдия

Π€ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ β€” ΠŸΠ°Ρ€Π°Π΄ΠΈΠ³ΠΌΡ‹ программирования АгСнтно ориСнтированная ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π½ΠΎ ориСнтированная ΠšΠΎΠ½ΠΊΠ°Ρ‚Π΅Π½Π°Ρ‚ΠΈΠ²Π½Π°Ρ ДСкларативная (контрастируСт с Π˜ΠΌΠΏΠ΅Ρ€Π°Ρ‚ΠΈΠ²Π½ΠΎΠΉ) ΠžΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΡΠΌΠΈ Π€ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½Π°Ρ ΠŸΠΎΡ‚ΠΎΠΊΠΎΠΌ Π΄Π°Π½Π½Ρ‹Ρ… Π’Π°Π±Π»ΠΈΡ‡Π½ΠΎ ориСнтированная (элСктронныС Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹) РСактивная … ВикипСдия

Π‘Ρ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€Π½ΠΎΠ΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ β€” Π­Ρ‚Π° ΡΡ‚Π°Ρ‚ΡŒΡ ΠΈΠ»ΠΈ Ρ€Π°Π·Π΄Π΅Π» нуТдаСтся Π² ΠΏΠ΅Ρ€Π΅Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅. ΠŸΠΎΠΆΠ°Π»ΡƒΠΉΡΡ‚Π°, ΡƒΠ»ΡƒΡ‡ΡˆΠΈΡ‚Π΅ ΡΡ‚Π°Ρ‚ΡŒΡŽ Π² соотвСтствии с ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌΠΈ написания статСй … ВикипСдия

Π¦ΠΈΠΊΠ» (ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅) β€” Π£ этого Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π° ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‚ ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠ΅ значСния, см. Ρ†ΠΈΠΊΠ». Π’ Π΄Π°Π½Π½ΠΎΠΉ ΡΡ‚Π°Ρ‚ΡŒΠ΅ ΠΈΠ»ΠΈ Ρ€Π°Π·Π΄Π΅Π»Π΅ имССтся список источников ΠΈΠ»ΠΈ Π²Π½Π΅ΡˆΠ½ΠΈΡ… … ВикипСдия

Π€ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π½Π° ΠŸΠΈΡ‚ΠΎΠ½Π΅ β€” Π€ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ являСтся ΠΎΠ΄Π½ΠΎΠΉ ΠΈΠ· ΠΏΠ°Ρ€Π°Π΄ΠΈΠ³ΠΌ, ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹Ρ… языком программирования Python. ΠžΡΠ½ΠΎΠ²Π½Ρ‹ΠΌΠΈ прСдпосылками для ΠΏΠΎΠ»Π½ΠΎΡ†Π΅Π½Π½ΠΎΠ³ΠΎ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ программирования Π² Python ΡΠ²Π»ΡΡŽΡ‚ΡΡ: Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π²Ρ‹ΡΡˆΠΈΡ… порядков, Ρ€Π°Π·Π²ΠΈΡ‚Ρ‹Π΅ срСдства… … ВикипСдия

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Π£Ρ€ΠΎΠΊ β„–8. Π‘Ρ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€Π° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌ

ΠšΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Π½Π°Ρ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° β€” это ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ инструкций, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΡΠΎΠΎΠ±Ρ‰Π°ΡŽΡ‚ ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Ρƒ, Ρ‡Ρ‚ΠΎ Π΅ΠΌΡƒ Π½ΡƒΠΆΠ½ΠΎ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ.

Π‘Ρ‚Π΅ΠΉΡ‚ΠΌΠ΅Π½Ρ‚Ρ‹

CΡ‚Π΅ΠΉΡ‚ΠΌΠ΅Π½Ρ‚ (Π°Π½Π³Π». Β«statementΒ») β€” это Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ распространСнный Ρ‚ΠΈΠΏ инструкций Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Ρ…. Π­Ρ‚ΠΎ ΠΈ Π΅ΡΡ‚ΡŒ Ρ‚Π° самая инструкция, наимСньшая нСзависимая Π΅Π΄ΠΈΠ½ΠΈΡ†Π° Π² языкС Π‘++. Π‘Ρ‚Π΅ΠΉΡ‚ΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ β€” это Ρ‚ΠΎ ΠΆΠ΅ самоС, Ρ‡Ρ‚ΠΎ ΠΈ Β«ΠΏΡ€Π΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅Β» Π² русском языкС. ΠœΡ‹ пишСм прСдлоТСния, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²Ρ‹Ρ€Π°Π·ΠΈΡ‚ΡŒ ΠΊΠ°ΠΊΡƒΡŽ-Ρ‚ΠΎ идСю. Π’ языкС C++ ΠΌΡ‹ пишСм стСйтмСнты, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ ΠΊΠ°ΠΊΠΎΠ΅-Ρ‚ΠΎ Π·Π°Π΄Π°Π½ΠΈΠ΅. ВсС стСйтмСнты Π² языкС C++ Π·Π°ΠΊΠ°Π½Ρ‡ΠΈΠ²Π°ΡŽΡ‚ΡΡ Ρ‚ΠΎΡ‡ΠΊΠΎΠΉ с запятой.

Π•ΡΡ‚ΡŒ ΠΌΠ½ΠΎΠ³ΠΎ Ρ€Π°Π·Π½Ρ‹Ρ… Π²ΠΈΠ΄ΠΎΠ² стСйтмСнтов Π² языкС C++. Рассмотрим самыС распространСнныС ΠΈΠ· Π½ΠΈΡ…:

int Ρ… β€” это стСйтмСнт объявлСния (Π°Π½Π³Π». Β«statement declarationΒ»). Он сообщаСт компилятору, Ρ‡Ρ‚ΠΎ Ρ… являСтся ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ. Π’ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ каТдая пСрСмСнная Π·Π°Π½ΠΈΠΌΠ°Π΅Ρ‚ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠ΅ число адрСсуСмых ячССк Π² памяти Π² зависимости ΠΎΡ‚ Π΅Ρ‘ Ρ‚ΠΈΠΏΠ°. Минимальная адрСсуСмая ячСйка β€” Π±Π°ΠΉΡ‚. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Π°Ρ Ρ‚ΠΈΠΏΠ° int ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°Π½ΠΈΠΌΠ°Ρ‚ΡŒ Π΄ΠΎ 4 Π±Π°ΠΉΡ‚, Ρ‚.Π΅. Π΄ΠΎ 4 адрСсуСмых ячССк памяти. ВсС ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ ΠΎΠ±ΡŠΡΠ²Π»Π΅Π½Ρ‹, ΠΏΡ€Π΅ΠΆΠ΄Π΅ Ρ‡Π΅ΠΌ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Π½Ρ‹. ΠœΡ‹ Π΄Π΅Ρ‚Π°Π»ΡŒΠ½ΠΎ ΠΏΠΎΠ³ΠΎΠ²ΠΎΡ€ΠΈΠΌ ΠΎ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… Π½Π° ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… ΡƒΡ€ΠΎΠΊΠ°Ρ….

std::cout β€” это стСйтмСнт Π²Ρ‹Π²ΠΎΠ΄Π° (Π°Π½Π³Π». Β«output statementΒ»). ΠœΡ‹ Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ Ρ… Π½Π° экран.

ВыраТСния

Π€ΡƒΠ½ΠΊΡ†ΠΈΠΈ

Π’ языкС C++ стСйтмСнты ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΡΡŽΡ‚ΡΡ Π² Π±Π»ΠΎΠΊΠΈ β€” Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ. Ѐункция β€” это ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ стСйтмСнтов. КаТдая ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°, написанная Π½Π° языкС C++, Π΄ΠΎΠ»ΠΆΠ½Π° ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ Π³Π»Π°Π²Π½ΡƒΡŽ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ main(). ИмСнно с ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ стСйтмСнта, находящСгося Π² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ main(), ΠΈ начинаСтся Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ всСй ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹. Π€ΡƒΠ½ΠΊΡ†ΠΈΠΈ, ΠΊΠ°ΠΊ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ, Π²Ρ‹ΠΏΠΎΠ»Π½ΡΡŽΡ‚ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠ΅ Π·Π°Π΄Π°Π½ΠΈΠ΅. НапримСр, функция max() ΠΌΠΎΠΆΠ΅Ρ‚ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ стСйтмСнты, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ большСС ΠΈΠ· Π·Π°Π΄Π°Π½Π½Ρ‹Ρ… чисСл, Π° функция calculateGrade() ΠΌΠΎΠΆΠ΅Ρ‚ Π²Ρ‹Ρ‡ΠΈΡΠ»ΡΡ‚ΡŒ ΡΡ€Π΅Π΄Π½ΡŽΡŽ ΠΎΡ†Π΅Π½ΠΊΡƒ студСнта ΠΏΠΎ ΠΊΠ°ΠΊΠΎΠΉ-Π»ΠΈΠ±ΠΎ дисциплинС.

Π‘ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ

Π‘ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ° β€” это Π½Π°Π±ΠΎΡ€ скомпилированного ΠΊΠΎΠ΄Π° (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ), ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π±Ρ‹Π» Β«ΡƒΠΏΠ°ΠΊΠΎΠ²Π°Π½Β» для ΠΏΠΎΠ²Ρ‚ΠΎΡ€Π½ΠΎΠ³ΠΎ использования Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Ρ…. Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊ ΠΌΠΎΠΆΠ½ΠΎ Ρ€Π°ΡΡˆΠΈΡ€ΠΈΡ‚ΡŒ возмоТности ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌ. НапримСр, Ссли Π²Ρ‹ ΠΏΠΈΡˆΠ΅Ρ‚Π΅ ΠΈΠ³Ρ€Ρƒ, Ρ‚ΠΎ Π²Π°ΠΌ придСтся ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Ρ‚ΡŒ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ Π·Π²ΡƒΠΊΠ° ΠΈΠ»ΠΈ Π³Ρ€Π°Ρ„ΠΈΠΊΠΈ (Ссли Π²Ρ‹ ΡΠ°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½ΠΎ Π½Π΅ Ρ…ΠΎΡ‚ΠΈΡ‚Π΅ ΠΈΡ… ΡΠΎΠ·Π΄Π°Π²Π°Ρ‚ΡŒ).

Π―Π·Ρ‹ΠΊ C++ Π½Π΅ Ρ‚Π°ΠΊΠΎΠΉ ΡƒΠΆ ΠΈ большой, ΠΊΠ°ΠΊ Π²Ρ‹ ΠΌΠΎΠ³Π»ΠΈ Π±Ρ‹ ΠΏΠΎΠ΄ΡƒΠΌΠ°Ρ‚ΡŒ. Π’Π΅ΠΌ Π½Π΅ ΠΌΠ΅Π½Π΅Π΅, ΠΎΠ½ ΠΈΠ΄Π΅Ρ‚ Π² ΠΊΠΎΠΌΠΏΠ»Π΅ΠΊΡ‚Π΅ со Π‘Ρ‚Π°Π½Π΄Π°Ρ€Ρ‚Π½ΠΎΠΉ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΎΠΉ Π‘++, которая прСдоставляСт Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π». Одной ΠΈΠ· Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ часто ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹Ρ… частСй Π‘Ρ‚Π°Π½Π΄Π°Ρ€Ρ‚Π½ΠΎΠΉ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ C++ являСтся Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ° iostream, которая позволяСт Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ΡŒ Π΄Π°Π½Π½Ρ‹Π΅ Π½Π° экран ΠΈ ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ Π²Π²ΠΎΠ΄.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ простой ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹

Π’Π΅ΠΏΠ΅Ρ€ΡŒ, ΠΊΠΎΠ³Π΄Π° Ρƒ вас Π΅ΡΡ‚ΡŒ ΠΎΠ±Ρ‰Π΅Π΅ прСдставлСниС ΠΎ Ρ‚ΠΎΠΌ, Ρ‡Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ стСйтмСнты, Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΈ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ, Π΄Π°Π²Π°ΠΉΡ‚Π΅ рассмотрим Π΅Ρ‰Π΅ Ρ€Π°Π· ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡƒ Β«Hello, world!Β»:

Π‘Ρ‚Ρ€ΠΎΠΊΠ° β„–1: Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΉ Ρ‚ΠΈΠΏ инструкции, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ называСтся Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²ΠΎΠΉ прСпроцСссора. Π”ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹ прСпроцСссора ΡΠΎΠΎΠ±Ρ‰Π°ΡŽΡ‚ компилятору, Ρ‡Ρ‚ΠΎ Π΅ΠΌΡƒ Π½ΡƒΠΆΠ½ΠΎ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠ΅ Π·Π°Π΄Π°Π½ΠΈΠ΅. Π’ этом случаС ΠΌΡ‹ Π³ΠΎΠ²ΠΎΡ€ΠΈΠΌ компилятору, Ρ‡Ρ‚ΠΎ Ρ…ΠΎΡ‚Π΅Π»ΠΈ Π±Ρ‹ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ содСрТимоС Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΡ‡Π½ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊ нашСй ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ΅. ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΡ‡Π½ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π° Π΄Π°Π΅Ρ‚ Π½Π°ΠΌ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π» Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ iostream, Ρ‡Ρ‚ΠΎ, Π² свою ΠΎΡ‡Π΅Ρ€Π΅Π΄ΡŒ, позволяСт Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ΡŒ Π½Π°ΠΌ Π΄Π°Π½Π½Ρ‹Π΅ Π½Π° экран.

Π‘Ρ‚Ρ€ΠΎΠΊΠ° β„–2: ΠŸΡƒΡΡ‚ΠΎΠ΅ пространство, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ игнорируСтся компилятором.

Π‘Ρ‚Ρ€ΠΎΠΊΠ° β„–3: ОбъявлСниС Π³Π»Π°Π²Π½ΠΎΠΉ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ main().

Π‘Ρ‚Ρ€ΠΎΠΊΠΈ β„–4 ΠΈ β„–7: Π£ΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ компилятору ΠΎΠ±Π»Π°ΡΡ‚ΡŒ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ main(). Всё, Ρ‡Ρ‚ΠΎ находится ΠΌΠ΅ΠΆΠ΄Ρƒ ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ Ρ„ΠΈΠ³ΡƒΡ€Π½ΠΎΠΉ скобкой Π² строкС β„–4 ΠΈ Π·Π°ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ Ρ„ΠΈΠ³ΡƒΡ€Π½ΠΎΠΉ скобкой Π² строкС β„–7 β€” считаСтся содСрТимым Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ main().

Π‘Ρ‚Ρ€ΠΎΠΊΠ° β„–6: ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Π²ΠΎΠ·Π²Ρ€Π°Ρ‚Π° return. Когда ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ своС Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅, функция main() ΠΏΠ΅Ρ€Π΅Π΄Π°Π΅Ρ‚ ΠΎΠ±Ρ€Π°Ρ‚Π½ΠΎ Π² ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΎΠ½Π½ΡƒΡŽ систСму Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Π½Π° Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹: ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ Π»ΠΈ ΠΏΡ€ΠΎΡˆΠ»ΠΎ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ ΠΈΠ»ΠΈ Π½Π΅Ρ‚.

Бинтаксис ΠΈ синтаксичСскиС ошибки

Как Π²Ρ‹, Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ, Π·Π½Π°Π΅Ρ‚Π΅, Π² русском языкС всС прСдлоТСния ΠΏΠΎΠ΄Ρ‡ΠΈΠ½ΡΡŽΡ‚ΡΡ ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌ Π³Ρ€Π°ΠΌΠΌΠ°Ρ‚ΠΈΠΊΠΈ. НапримСр, ΠΊΠ°ΠΆΠ΄ΠΎΠ΅ ΠΏΡ€Π΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π·Π°ΠΊΠ°Π½Ρ‡ΠΈΠ²Π°Ρ‚ΡŒΡΡ Ρ‚ΠΎΡ‡ΠΊΠΎΠΉ. ΠŸΡ€Π°Π²ΠΈΠ»Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Ρ€Π΅Π³ΡƒΠ»ΠΈΡ€ΡƒΡŽΡ‚ построСниС ΠΏΡ€Π΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠΉ, Π½Π°Π·Ρ‹Π²Π°ΡŽΡ‚ΡΡ синтаксисом. Если Π²Ρ‹ Π½Π΅ поставили Ρ‚ΠΎΡ‡ΠΊΡƒ ΠΈ записали Π΄Π²Π° прСдлоТСния подряд, Ρ‚ΠΎ это являСтся Π½Π°Ρ€ΡƒΡˆΠ΅Π½ΠΈΠ΅ΠΌ синтаксиса русского языка.

Π―Π·Ρ‹ΠΊ C++ Ρ‚Π°ΠΊΠΆΠ΅ ΠΈΠΌΠ΅Π΅Ρ‚ свой синтаксис: ΠΏΡ€Π°Π²ΠΈΠ»Π° написания ΠΊΠΎΠ΄Π°/ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌ. ΠŸΡ€ΠΈ компиляции вашСй ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, компилятор ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ Π·Π° Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ваша ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° соотвСтствовала ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌ синтаксиса языка C++. Если Π²Ρ‹ Π½Π°Ρ€ΡƒΡˆΠΈΠ»ΠΈ ΠΏΡ€Π°Π²ΠΈΠ»Π°, Ρ‚ΠΎ компилятор Π±ΡƒΠ΄Π΅Ρ‚ Ρ€ΡƒΠ³Π°Ρ‚ΡŒΡΡ ΠΈ выдаст Π²Π°ΠΌ ΠΎΡˆΠΈΠ±ΠΊΡƒ.

НапримСр, Π΄Π°Π²Π°ΠΉΡ‚Π΅ посмотрим, Ρ‡Ρ‚ΠΎ ΠΏΡ€ΠΎΠΈΠ·ΠΎΠΉΠ΄Π΅Ρ‚, Ссли ΠΌΡ‹ Π½Π΅ ΡƒΠΊΠ°ΠΆΠ΅ΠΌ Π² ΠΊΠΎΠ½Ρ†Π΅ стСйтмСнта Ρ‚ΠΎΡ‡ΠΊΡƒ с запятой:

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Statements

C# provides a variety of statements. Most of these statements will be familiar to developers who have programmed in C and C++.

The embedded_statement nonterminal is used for statements that appear within other statements. The use of embedded_statement rather than statement excludes the use of declaration statements and labeled statements in these contexts. The example

results in a compile-time error because an if statement requires an embedded_statement rather than a statement for its if branch. If this code were permitted, then the variable i would be declared, but it could never be used. Note, however, that by placing i ‘s declaration in a block, the example is valid.

End points and reachability

Every statement has an end point. In intuitive terms, the end point of a statement is the location that immediately follows the statement. The execution rules for composite statements (statements that contain embedded statements) specify the action that is taken when control reaches the end point of an embedded statement. For example, when control reaches the end point of a statement in a block, control is transferred to the next statement in the block.

If a statement can possibly be reached by execution, the statement is said to be reachable. Conversely, if there is no possibility that a statement will be executed, the statement is said to be unreachable.

the second invocation of Console.WriteLine is unreachable because there is no possibility that the statement will be executed.

A warning is reported if the compiler determines that a statement is unreachable. It is specifically not an error for a statement to be unreachable.

To determine whether a particular statement or end point is reachable, the compiler performs flow analysis according to the reachability rules defined for each statement. The flow analysis takes into account the values of constant expressions (Constant expressions) that control the behavior of statements, but the possible values of non-constant expressions are not considered. In other words, for purposes of control flow analysis, a non-constant expression of a given type is considered to have any possible value of that type.

the Console.WriteLine invocation is considered reachable, even though, in reality, it will never be executed.

The block of a function member is always considered reachable. By successively evaluating the reachability rules of each statement in a block, the reachability of any given statement can be determined.

the reachability of the second Console.WriteLine is determined as follows:

There are two situations in which it is a compile-time error for the end point of a statement to be reachable:

Blocks

A block permits multiple statements to be written in contexts where a single statement is allowed.

A block consists of an optional statement_list (Statement lists), enclosed in braces. If the statement list is omitted, the block is said to be empty.

A block may contain declaration statements (Declaration statements). The scope of a local variable or constant declared in a block is the block.

A block is executed as follows:

The statement list of a block is reachable if the block itself is reachable.

The end point of a block is reachable if the block is empty or if the end point of the statement list is reachable.

A block that contains one or more yield statements (The yield statement) is called an iterator block. Iterator blocks are used to implement function members as iterators (Iterators). Some additional restrictions apply to iterator blocks:

Statement lists

A statement list consists of one or more statements written in sequence. Statement lists occur in blocks (Blocks) and in switch_blocks (The switch statement).

A statement list is executed by transferring control to the first statement. When and if control reaches the end point of a statement, control is transferred to the next statement. When and if control reaches the end point of the last statement, control is transferred to the end point of the statement list.

A statement in a statement list is reachable if at least one of the following is true:

The end point of a statement list is reachable if the end point of the last statement in the list is reachable.

The empty statement

An empty_statement does nothing.

An empty statement is used when there are no operations to perform in a context where a statement is required.

Execution of an empty statement simply transfers control to the end point of the statement. Thus, the end point of an empty statement is reachable if the empty statement is reachable.

An empty statement can be used when writing a while statement with a null body:

Also, an empty statement can be used to declare a label just before the closing » > » of a block:

Labeled statements

A labeled_statement permits a statement to be prefixed by a label. Labeled statements are permitted in blocks, but are not permitted as embedded statements.

A labeled statement declares a label with the name given by the identifier. The scope of a label is the whole block in which the label is declared, including any nested blocks. It is a compile-time error for two labels with the same name to have overlapping scopes.

A label can be referenced from goto statements (The goto statement) within the scope of the label. This means that goto statements can transfer control within blocks and out of blocks, but never into blocks.

Labels have their own declaration space and do not interfere with other identifiers. The example

is valid and uses the name x as both a parameter and a label.

Execution of a labeled statement corresponds exactly to execution of the statement following the label.

Declaration statements

A declaration_statement declares a local variable or constant. Declaration statements are permitted in blocks, but are not permitted as embedded statements.

Local variable declarations

A local_variable_declaration declares one or more local variables.

The local_variable_type of a local_variable_declaration either directly specifies the type of the variables introduced by the declaration, or indicates with the identifier var that the type should be inferred based on an initializer. The type is followed by a list of local_variable_declarators, each of which introduces a new variable. A local_variable_declarator consists of an identifier that names the variable, optionally followed by an » = » token and a local_variable_initializer that gives the initial value of the variable.

In the context of a local variable declaration, the identifier var acts as a contextual keyword (Keywords).When the local_variable_type is specified as var and no type named var is in scope, the declaration is an implicitly typed local variable declaration, whose type is inferred from the type of the associated initializer expression. Implicitly typed local variable declarations are subject to the following restrictions:

The following are examples of incorrect implicitly typed local variable declarations:

The value of a local variable is obtained in an expression using a simple_name (Simple names), and the value of a local variable is modified using an assignment (Assignment operators). A local variable must be definitely assigned (Definite assignment) at each location where its value is obtained.

The scope of a local variable declared in a local_variable_declaration is the block in which the declaration occurs. It is an error to refer to a local variable in a textual position that precedes the local_variable_declarator of the local variable. Within the scope of a local variable, it is a compile-time error to declare another local variable or constant with the same name.

A local variable declaration that declares multiple variables is equivalent to multiple declarations of single variables with the same type. Furthermore, a variable initializer in a local variable declaration corresponds exactly to an assignment statement that is inserted immediately after the declaration.

corresponds exactly to

In an implicitly typed local variable declaration, the type of the local variable being declared is taken to be the same as the type of the expression used to initialize the variable. For example:

The implicitly typed local variable declarations above are precisely equivalent to the following explicitly typed declarations:

Local constant declarations

A local_constant_declaration declares one or more local constants.

The type of a local_constant_declaration specifies the type of the constants introduced by the declaration. The type is followed by a list of constant_declarators, each of which introduces a new constant. A constant_declarator consists of an identifier that names the constant, followed by an » = » token, followed by a constant_expression (Constant expressions) that gives the value of the constant.

The type and constant_expression of a local constant declaration must follow the same rules as those of a constant member declaration (Constants).

The value of a local constant is obtained in an expression using a simple_name (Simple names).

The scope of a local constant is the block in which the declaration occurs. It is an error to refer to a local constant in a textual position that precedes its constant_declarator. Within the scope of a local constant, it is a compile-time error to declare another local variable or constant with the same name.

A local constant declaration that declares multiple constants is equivalent to multiple declarations of single constants with the same type.

Expression statements

An expression_statement evaluates a given expression. The value computed by the expression, if any, is discarded.

Not all expressions are permitted as statements. In particular, expressions such as x + y and x == 1 that merely compute a value (which will be discarded), are not permitted as statements.

Execution of an expression_statement evaluates the contained expression and then transfers control to the end point of the expression_statement. The end point of an expression_statement is reachable if that expression_statement is reachable.

Selection statements

Selection statements select one of a number of possible statements for execution based on the value of some expression.

The if statement

The if statement selects a statement for execution based on the value of a boolean expression.

An else part is associated with the lexically nearest preceding if that is allowed by the syntax. Thus, an if statement of the form

An if statement is executed as follows:

The switch statement

The switch statement selects for execution a statement list having an associated switch label that corresponds to the value of the switch expression.

The governing type of a switch statement is established by the switch expression.

The constant expression of each case label must denote a value that is implicitly convertible (Implicit conversions) to the governing type of the switch statement. A compile-time error occurs if two or more case labels in the same switch statement specify the same constant value.

There can be at most one default label in a switch statement.

A switch statement is executed as follows:

If the end point of the statement list of a switch section is reachable, a compile-time error occurs. This is known as the «no fall through» rule. The example

is valid because no switch section has a reachable end point. Unlike C and C++, execution of a switch section is not permitted to «fall through» to the next switch section, and the example

results in a compile-time error. When execution of a switch section is to be followed by execution of another switch section, an explicit goto case or goto default statement must be used:

Multiple labels are permitted in a switch_section. The example

is valid. The example does not violate the «no fall through» rule because the labels case 2: and default: are part of the same switch_section.

The «no fall through» rule prevents a common class of bugs that occur in C and C++ when break statements are accidentally omitted. In addition, because of this rule, the switch sections of a switch statement can be arbitrarily rearranged without affecting the behavior of the statement. For example, the sections of the switch statement above can be reversed without affecting the behavior of the statement:

Like the string equality operators (String equality operators), the switch statement is case sensitive and will execute a given switch section only if the switch expression string exactly matches a case label constant.

The statement_lists of a switch_block may contain declaration statements (Declaration statements). The scope of a local variable or constant declared in a switch block is the switch block.

The statement list of a given switch section is reachable if the switch statement is reachable and at least one of the following is true:

The end point of a switch statement is reachable if at least one of the following is true:

Iteration statements

Iteration statements repeatedly execute an embedded statement.

The while statement

The while statement conditionally executes an embedded statement zero or more times.

A while statement is executed as follows:

Within the embedded statement of a while statement, a break statement (The break statement) may be used to transfer control to the end point of the while statement (thus ending iteration of the embedded statement), and a continue statement (The continue statement) may be used to transfer control to the end point of the embedded statement (thus performing another iteration of the while statement).

The end point of a while statement is reachable if at least one of the following is true:

The do statement

The do statement conditionally executes an embedded statement one or more times.

A do statement is executed as follows:

Within the embedded statement of a do statement, a break statement (The break statement) may be used to transfer control to the end point of the do statement (thus ending iteration of the embedded statement), and a continue statement (The continue statement) may be used to transfer control to the end point of the embedded statement.

The embedded statement of a do statement is reachable if the do statement is reachable.

The end point of a do statement is reachable if at least one of the following is true:

The for statement

The for statement evaluates a sequence of initialization expressions and then, while a condition is true, repeatedly executes an embedded statement and evaluates a sequence of iteration expressions.

The for_initializer, if present, consists of either a local_variable_declaration (Local variable declarations) or a list of statement_expressions (Expression statements) separated by commas. The scope of a local variable declared by a for_initializer starts at the local_variable_declarator for the variable and extends to the end of the embedded statement. The scope includes the for_condition and the for_iterator.

The for_condition, if present, must be a boolean_expression (Boolean expressions).

The for_iterator, if present, consists of a list of statement_expressions (Expression statements) separated by commas.

A for statement is executed as follows:

Within the embedded statement of a for statement, a break statement (The break statement) may be used to transfer control to the end point of the for statement (thus ending iteration of the embedded statement), and a continue statement (The continue statement) may be used to transfer control to the end point of the embedded statement (thus executing the for_iterator and performing another iteration of the for statement, starting with the for_condition).

The embedded statement of a for statement is reachable if one of the following is true:

The end point of a for statement is reachable if at least one of the following is true:

The foreach statement

The foreach statement enumerates the elements of a collection, executing an embedded statement for each element of the collection.

The compile-time processing of a foreach statement first determines the collection type, enumerator type and element type of the expression. This determination proceeds as follows:

Otherwise, determine whether the type X has an appropriate GetEnumerator method:

Otherwise, check for an enumerable interface:

is then expanded to:

An implementation is permitted to implement a given foreach-statement differently, e.g. for performance reasons, as long as the behavior is consistent with the above expansion.

The placement of v inside the while loop is important for how it is captured by any anonymous function occurring in the embedded_statement.

The body of the finally block is constructed according to the following steps:

If there is an implicit conversion from E to the System.IDisposable interface, then

If E is a non-nullable value type then the finally clause is expanded to the semantic equivalent of:

Otherwise the finally clause is expanded to the semantic equivalent of:

except that if E is a value type, or a type parameter instantiated to a value type, then the cast of e to System.IDisposable will not cause boxing to occur.

Otherwise, if E is a sealed type, the finally clause is expanded to an empty block:

Otherwise, the finally clause is expanded to:

The local variable d is not visible to or accessible to any user code. In particular, it does not conflict with any other variable whose scope includes the finally block.

The following example prints out each value in a two-dimensional array, in element order:

The output produced is as follows:

Jump statements

Jump statements unconditionally transfer control.

The location to which a jump statement transfers control is called the target of the jump statement.

When a jump statement occurs within a block, and the target of that jump statement is outside that block, the jump statement is said to exit the block. While a jump statement may transfer control out of a block, it can never transfer control into a block.

Execution of jump statements is complicated by the presence of intervening try statements. In the absence of such try statements, a jump statement unconditionally transfers control from the jump statement to its target. In the presence of such intervening try statements, execution is more complex. If the jump statement exits one or more try blocks with associated finally blocks, control is initially transferred to the finally block of the innermost try statement. When and if control reaches the end point of a finally block, control is transferred to the finally block of the next enclosing try statement. This process is repeated until the finally blocks of all intervening try statements have been executed.

the finally blocks associated with two try statements are executed before control is transferred to the target of the jump statement.

The output produced is as follows:

The break statement

A break statement cannot exit a finally block (The try statement). When a break statement occurs within a finally block, the target of the break statement must be within the same finally block; otherwise, a compile-time error occurs.

A break statement is executed as follows:

Because a break statement unconditionally transfers control elsewhere, the end point of a break statement is never reachable.

The continue statement

A continue statement cannot exit a finally block (The try statement). When a continue statement occurs within a finally block, the target of the continue statement must be within the same finally block; otherwise a compile-time error occurs.

A continue statement is executed as follows:

Because a continue statement unconditionally transfers control elsewhere, the end point of a continue statement is never reachable.

The goto statement

The goto statement transfers control to a statement that is marked by a label.

The target of a goto identifier statement is the labeled statement with the given label. If a label with the given name does not exist in the current function member, or if the goto statement is not within the scope of the label, a compile-time error occurs. This rule permits the use of a goto statement to transfer control out of a nested scope, but not into a nested scope. In the example

a goto statement is used to transfer control out of a nested scope.

The target of a goto case statement is the statement list in the immediately enclosing switch statement (The switch statement), which contains a case label with the given constant value. If the goto case statement is not enclosed by a switch statement, if the constant_expression is not implicitly convertible (Implicit conversions) to the governing type of the nearest enclosing switch statement, or if the nearest enclosing switch statement does not contain a case label with the given constant value, a compile-time error occurs.

The target of a goto default statement is the statement list in the immediately enclosing switch statement (The switch statement), which contains a default label. If the goto default statement is not enclosed by a switch statement, or if the nearest enclosing switch statement does not contain a default label, a compile-time error occurs.

A goto statement cannot exit a finally block (The try statement). When a goto statement occurs within a finally block, the target of the goto statement must be within the same finally block, or otherwise a compile-time error occurs.

A goto statement is executed as follows:

Because a goto statement unconditionally transfers control elsewhere, the end point of a goto statement is never reachable.

The return statement

The return statement returns control to the current caller of the function in which the return statement appears.

A return statement with an expression can only be used in a function member that computes a value, that is, a method with a non-void result type, the get accessor of a property or indexer, or a user-defined operator. An implicit conversion (Implicit conversions) must exist from the type of the expression to the return type of the containing function member.

Return statements can also be used in the body of anonymous function expressions (Anonymous function expressions), and participate in determining which conversions exist for those functions.

It is a compile-time error for a return statement to appear in a finally block (The try statement).

A return statement is executed as follows:

Because a return statement unconditionally transfers control elsewhere, the end point of a return statement is never reachable.

The throw statement

The throw statement throws an exception.

A throw statement with no expression can be used only in a catch block, in which case that statement re-throws the exception that is currently being handled by that catch block.

Because a throw statement unconditionally transfers control elsewhere, the end point of a throw statement is never reachable.

When an exception is thrown, control is transferred to the first catch clause in an enclosing try statement that can handle the exception. The process that takes place from the point of the exception being thrown to the point of transferring control to a suitable exception handler is known as exception propagation. Propagation of an exception consists of repeatedly evaluating the following steps until a catch clause that matches the exception is found. In this description, the throw point is initially the location at which the exception is thrown.

If the try block of S encloses the throw point and if S has one or more catch clauses, the catch clauses are examined in order of appearance to locate a suitable handler for the exception, according to the rules specified in Section The try statement. If a matching catch clause is located, the exception propagation is completed by transferring control to the block of that catch clause.

Otherwise, if the try block or a catch block of S encloses the throw point and if S has a finally block, control is transferred to the finally block. If the finally block throws another exception, processing of the current exception is terminated. Otherwise, when control reaches the end point of the finally block, processing of the current exception is continued.

If an exception handler was not located in the current function invocation, the function invocation is terminated, and one of the following occurs:

If the current function is non-async, the steps above are repeated for the caller of the function with a throw point corresponding to the statement from which the function member was invoked.

If the current function is async and task-returning, the exception is recorded in the return task, which is put into a faulted or cancelled state as described in Enumerator interfaces.

If the current function is async and void-returning, the synchronization context of the current thread is notified as described in Enumerable interfaces.

If the exception processing terminates all function member invocations in the current thread, indicating that the thread has no handler for the exception, then the thread is itself terminated. The impact of such termination is implementation-defined.

The try statement

The try statement provides a mechanism for catching exceptions that occur during execution of a block. Furthermore, the try statement provides the ability to specify a block of code that is always executed when control leaves the try statement.

There are three possible forms of try statements:

When a catch clause specifies both an exception_specifier with an identifier, an exception variable of the given name and type is declared. The exception variable corresponds to a local variable with a scope that extends over the catch clause. During execution of the exception_filter and block, the exception variable represents the exception currently being handled. For purposes of definite assignment checking, the exception variable is considered definitely assigned in its entire scope.

Unless a catch clause includes an exception variable name, it is impossible to access the exception object in the filter and catch block.

A catch clause that does not specify an exception_specifier is called a general catch clause.

In order to locate a handler for an exception, catch clauses are examined in lexical order. If a catch clause specifies a type but no exception filter, it is a compile-time error for a later catch clause in the same try statement to specify a type that is the same as, or is derived from, that type. If a catch clause specifies no type and no filter, it must be the last catch clause for that try statement.

Within a catch block, a throw statement (The throw statement) with no expression can be used to re-throw the exception that was caught by the catch block. Assignments to an exception variable do not alter the exception that is re-thrown.

the method F catches an exception, writes some diagnostic information to the console, alters the exception variable, and re-throws the exception. The exception that is re-thrown is the original exception, so the output produced is:

If the first catch block had thrown e instead of rethrowing the current exception, the output produced would be as follows:

It is a compile-time error for a return statement to occur in a finally block.

A try statement is executed as follows:

Control is transferred to the try block.

When and if control reaches the end point of the try block:

If an exception is propagated to the try statement during execution of the try block:

If an exception is thrown during execution of a finally block, and is not caught within the same finally block, the exception is propagated to the next enclosing try statement. If another exception was in the process of being propagated, that exception is lost. The process of propagating an exception is discussed further in the description of the throw statement (The throw statement).

The try block of a try statement is reachable if the try statement is reachable.

A catch block of a try statement is reachable if the try statement is reachable.

The finally block of a try statement is reachable if the try statement is reachable.

The end point of a try statement is reachable if both of the following are true:

The checked and unchecked statements

The checked and unchecked statements are used to control the overflow checking context for integral-type arithmetic operations and conversions.

The checked statement causes all expressions in the block to be evaluated in a checked context, and the unchecked statement causes all expressions in the block to be evaluated in an unchecked context.

The checked and unchecked statements are precisely equivalent to the checked and unchecked operators (The checked and unchecked operators), except that they operate on blocks instead of expressions.

The lock statement

The lock statement obtains the mutual-exclusion lock for a given object, executes a statement, and then releases the lock.

The expression of a lock statement must denote a value of a type known to be a reference_type. No implicit boxing conversion (Boxing conversions) is ever performed for the expression of a lock statement, and thus it is a compile-time error for the expression to denote a value of a value_type.

A lock statement of the form

where x is an expression of a reference_type, is precisely equivalent to

except that x is only evaluated once.

While a mutual-exclusion lock is held, code executing in the same execution thread can also obtain and release the lock. However, code executing in other threads is blocked from obtaining the lock until the lock is released.

Locking System.Type objects in order to synchronize access to static data is not recommended. Other code might lock on the same type, which can result in deadlock. A better approach is to synchronize access to static data by locking a private static object. For example:

The using statement

The using statement obtains one or more resources, executes a statement, and then disposes of the resource.

A using statement is translated into three parts: acquisition, usage, and disposal. Usage of the resource is implicitly enclosed in a try statement that includes a finally clause. This finally clause disposes of the resource. If a null resource is acquired, then no call to Dispose is made, and no exception is thrown. If the resource is of type dynamic it is dynamically converted through an implicit dynamic conversion (Implicit dynamic conversions) to IDisposable during acquisition in order to ensure that the conversion is successful before the usage and disposal.

A using statement of the form

corresponds to one of three possible expansions. When ResourceType is a non-nullable value type, the expansion is

In either expansion, the resource variable is read-only in the embedded statement, and the d variable is inaccessible in, and invisible to, the embedded statement.

An implementation is permitted to implement a given using-statement differently, e.g. for performance reasons, as long as the behavior is consistent with the above expansion.

A using statement of the form

When a resource_acquisition takes the form of a local_variable_declaration, it is possible to acquire multiple resources of a given type. A using statement of the form

is precisely equivalent to a sequence of nested using statements:

The example below creates a file named log.txt and writes two lines of text to the file. The example then opens that same file for reading and copies the contained lines of text to the console.

Since the TextWriter and TextReader classes implement the IDisposable interface, the example can use using statements to ensure that the underlying file is properly closed following the write or read operations.

The yield statement

The yield statement is used in an iterator block (Blocks) to yield a value to the enumerator object (Enumerator objects) or enumerable object (Enumerable objects) of an iterator or to signal the end of the iteration.

yield is not a reserved word; it has special meaning only when used immediately before a return or break keyword. In other contexts, yield can be used as an identifier.

There are several restrictions on where a yield statement can appear, as described in the following.

The following example shows some valid and invalid uses of yield statements.

An implicit conversion (Implicit conversions) must exist from the type of the expression in the yield return statement to the yield type (Yield type) of the iterator.

A yield return statement is executed as follows:

The next call to the enumerator object’s MoveNext method resumes execution of the iterator block from where it was last suspended.

A yield break statement is executed as follows:

Because a yield break statement unconditionally transfers control elsewhere, the end point of a yield break statement is never reachable.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

Π’Π°Ρˆ адрСс email Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½. ΠžΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ поля ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Ρ‹ *