Π§ΡΠΎ ΡΠ°ΠΊΠΎΠ΅ 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 ) β Π½Π°ΠΈΠΌΠ΅Π½ΡΡΠ°Ρ Π°Π²ΡΠΎΠ½ΠΎΠΌΠ½Π°Ρ ΡΠ°ΡΡΡ ΡΠ·ΡΠΊΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ; ΠΊΠΎΠΌΠ°Π½Π΄Π°. ΠΡΠΎΠ³ΡΠ°ΠΌΠΌΠ° ΠΎΠ±ΡΡΠ½ΠΎ ΠΏΡΠ΅Π΄ΡΡΠ°Π²Π»ΡΠ΅Ρ ΡΠΎΠ±ΠΎΠΉ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΠΎΡΡΡ ΠΈΠ½ΡΡΡΡΠΊΡΠΈΠΉ.
ΠΠ½ΠΎΠ³ΠΈΠ΅ ΡΠ·ΡΠΊΠΈ (Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ, Π‘ΠΈ) ΡΠ°Π·Π»ΠΈΡΠ°ΡΡ ΠΈΠ½ΡΡΡΡΠΊΡΠΈΡ ΠΈ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅. Π Π°Π·Π»ΠΈΡΠΈΠ΅ Π² ΡΠΎΠΌ, ΡΡΠΎ ΠΈΠ½ΡΡΡΡΠΊΡΠΈΡ ΠΈΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΊΠΎΠ΄, Π° ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΡΠΎΠ·Π΄Π°ΡΡ ΠΈΠ΄Π΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΎΡ (ΡΠΎ Π΅ΡΡΡ ΠΌΠΎΠΆΠ½ΠΎ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°ΡΡ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΊΠ°ΠΊ ΠΈΠ½ΡΡΡΡΠΊΡΠΈΡ ΠΏΡΠΈΡΠ²Π°ΠΈΠ²Π°Π½ΠΈΡ).
ΠΠΈΠΆΠ΅ ΠΏΡΠΈΠ²Π΅Π΄Π΅Π½Ρ ΠΎΡΠ½ΠΎΠ²Π½ΡΠ΅ ΠΎΠ±ΡΠΈΠ΅ ΠΈΠ½ΡΡΡΡΠΊΡΠΈΠΈ ΠΈΠΌΠΏΠ΅ΡΠ°ΡΠΈΠ²Π½ΡΡ ΡΠ·ΡΠΊΠΎΠ² ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ.
Π‘ΠΌ. ΡΠ°ΠΊΠΆΠ΅
ΠΠΎΠ»Π΅Π·Π½ΠΎΠ΅
Π‘ΠΌΠΎΡΡΠ΅ΡΡ ΡΡΠΎ ΡΠ°ΠΊΠΎΠ΅ «ΠΠΏΠ΅ΡΠ°ΡΠΎΡ (ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅)» Π² Π΄ΡΡΠ³ΠΈΡ ΡΠ»ΠΎΠ²Π°ΡΡΡ :
ΠΠΏΠ΅ΡΠ°ΡΠΎΡ β Π ΠΠΈΠΊΠΈΡΠ»ΠΎΠ²Π°ΡΠ΅ Π΅ΡΡΡ ΡΡΠ°ΡΡΡ Β«ΠΎΠΏΠ΅ΡΠ°ΡΠΎΡΒ» ΠΠΏΠ΅ΡΠ°ΡΠΎΡ ΠΌΠΎΠΆΠ΅Ρ ΠΎΠ·Π½Π°ΡΠ°ΡΡ: ΠΠΏΠ΅ΡΠ°ΡΠΎΡ (ΠΌΠ°ΡΠ΅ΠΌΠ°ΡΠΈΠΊΠ°) ΡΠΎ ΠΆΠ΅, ΡΡΠΎ ΠΌΠ°ΡΠ΅ΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠ°Ρ ΡΡΠ½ΠΊΡΠΈΡ; ΠΠΏΠ΅ΡΠ°ΡΠΎΡ (Π±ΠΈΠΎΠ»ΠΎΠ³ΠΈΡ) ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΠΎΡΡΡ ΠΠΠ, ΠΏΡΠΈΠ½ΠΈΠΌΠ°ΡΡΠ°Ρ ΡΡΠ°ΡΡΠΈΠ΅ Π² ΡΠ΅Π³ΡΠ»ΡΡΠΈΠΈ Π°ΠΊΡΠΈΠ²Π½ΠΎΡΡΠΈ Π³Π΅Π½ΠΎΠ²; ΠΠΏΠ΅ΡΠ°ΡΠΎΡβ¦ β¦ ΠΠΈΠΊΠΈΠΏΠ΅Π΄ΠΈΡ
ΠΎΠΏΠ΅ΡΠ°ΡΠΎΡ β 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.