กลับไปหน้าบทความ

อ่าน 6 นาที

การเปรียบเทียบภาษาโปรแกรม (คำสั่งพื้นฐาน)

บทความนี้เปรียบเทียบ ภาษาโปรแกรมจำนวนมากโดยแสดงตารางประเภทข้อมูลไวยากรณ์การแสดงนิพจน์ คำสั่งและการประกาศตัวแปรรวมถึงส่วนต่อประสานระบบปฏิบัติการทั่วไปบางส่วน

การเปรียบเทียบภาษาโปรแกรม (คำสั่งพื้นฐาน)

บทความนี้เปรียบเทียบ ภาษาโปรแกรมจำนวนมากโดยแสดงตารางประเภทข้อมูลไวยากรณ์การแสดงนิพจน์ คำสั่งและการประกาศตัวแปรรวมถึงส่วนต่อประสานระบบปฏิบัติการทั่วไปบางส่วน

หลักเกณฑ์ของบทความนี้

โดยทั่วไป`var` , `var`หรือ`var`เป็นวิธีแสดงชื่อตัวแปรหรือค่าที่ไม่ใช่ค่าตัวอักษรที่ผู้อ่านต้องตีความ ส่วนที่เหลือเป็นโค้ดตัวอักษร เครื่องหมาย ` guillemets` ( «และ») ใช้สำหรับล้อมรอบส่วนที่ไม่จำเป็น `<br>` Tab ↹แสดงถึงการเยื้องที่จำเป็น (ช่องว่าง)

โดยค่าเริ่มต้น ตารางไม่ได้เรียงลำดับตามชื่อภาษาโปรแกรมจากน้อยไปมาก และบางภาษามีรายการอยู่ในบางตารางแต่ไม่มีในตารางอื่น

ตัวระบุประเภท

8 บิต ( ไบต์ ) 16 บิต ( จำนวนเต็มสั้น ) 32 บิต 64 บิต ( จำนวนเต็มยาว ) ขนาดคำ แม่นยำตามอำเภอใจ ( บิ๊กนัม )
ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น
อาดา[ 1 ]range-2**7..2**7-1[จ]range0..2**8-1[j]หรือ [k]mod2**8range-2**15..2**15-1[จ]range0..2**16-1[j]หรือ [k]mod2**16range-2**31..2**31-1[จ]range0..2**32-1[j]หรือ [k]mod2**32range-2**63..2**63-1[จ]mod2**64[k]Integer[จ]range0..2**Integer'Size-1[j]หรือ [k]modInteger'Sizeไม่มีข้อมูล
ALGOL 68 (ความกว้างแปรผันได้) short short int[ค]ไม่มีข้อมูล short int[ค]ไม่มีข้อมูล int[ค]ไม่มีข้อมูล long int[ค]ไม่มีข้อมูล int[ค]ไม่มีข้อมูล long long int[ก] [ก]
bytesและbits
C ( C99ความกว้างคงที่) int8_tuint8_tint16_tuint16_tint32_tuint32_tint64_tuint64_tintptr_t[ค]size_t[ค]ไม่มีข้อมูล
C++ ( C++11ความกว้างคงที่)
C ( C99ความกว้างแปรผัน) signed charunsigned char( C++byte 17 ) short[ค]unsigned short[ค]long[ค]unsigned long[ค]long long[ค]unsigned long long[ค]int[ค]unsigned int[ค]
C++ ( C++11ความกว้างตัวแปร)
ออบเจกทีฟซี ( โกโก้ ) signed charหรือint8_tunsigned charหรือuint8_tshortหรือint16_tunsigned shortหรือuint16_tintหรือint32_tunsigned intหรือuint32_tlong longหรือint64_tunsigned long longหรือuint64_tNSIntegerหรือlongNSUIntegerหรือunsigned long
ซี#sbytebyteshortushortintuintlongulongIntPtrUIntPtrSystem.Numerics.BigInteger(.NET 4.0)
คริสตัลInt8UInt8Int16UInt16Int32UInt32Int64UInt64ไม่มีข้อมูล ไม่มีข้อมูล BigInt(ต้องระบุอย่างชัดเจน)
ชวาbyteไม่มีข้อมูล shortchar[ข]intไม่มีข้อมูล longไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล java.math.BigInteger
ไปint8uint8หรือbyteint16uint16int32uint32int64uint64intuintbig.Int
สนิมi8u8i16u16i32u32i64u64isizeusizeไม่มีข้อมูล
สวิฟต์Int8UInt8Int16UInt16Int32UInt32Int64UInt64IntUInt
ดีbyteubyteshortushortintuintlongulongไม่มีข้อมูล ไม่มีข้อมูล BigInt
ลิสป์สามัญ[ 2 ](signed-byte 8)(unsigned-byte 8)(signed-byte 16)(unsigned-byte 16)(signed-byte 32)(unsigned-byte 32)(signed-byte 64)(unsigned-byte 64)bignum
โครงการ
ISLISP [ 3 ]bignum
ปาสคาล ( FPC ) shortintbytesmallintwordlongintlongwordint64qwordintegercardinalไม่มีข้อมูล
วิชวลเบสไม่มีข้อมูล ByteIntegerไม่มีข้อมูล Longไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล
Visual Basic .NETSByteShortUShortIntegerUIntegerLongULongSystem.Numerics.BigInteger(.NET 4.0)
ฟรีเบสิกByteหรือInteger<8>UByteหรือUInteger<8>ShortหรือInteger<16>UShortหรือUInteger<16>LongหรือInteger<32>ULongหรือUInteger<32>LongIntหรือInteger<64>ULongIntหรือUInteger<64>IntegerUIntegerไม่มีข้อมูล
ไพธอน 2.x ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล intไม่มีข้อมูล long
ไพธอน 3.x ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล int
เอส-ลังไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล
ฟอร์ทรานINTEGER(KIND=n)[f]ไม่มีข้อมูล INTEGER(KIND=n)[f]ไม่มีข้อมูล INTEGER(KIND=n)[f]ไม่มีข้อมูล INTEGER(KIND=n)[f]ไม่มีข้อมูล
พีพีไม่มีข้อมูล ไม่มีข้อมูล int[ม]ไม่มีข้อมูล int[ม]ไม่มีข้อมูล ไม่มีข้อมูล [e]
เพิร์ล 5 ไม่มีข้อมูล[d]ไม่มีข้อมูล[d]ไม่มีข้อมูล[d]ไม่มีข้อมูล[d]ไม่มีข้อมูล[d]Math::BigInt
ราคุint8uint8int16uint16int32uint32int64uint64Intไม่มีข้อมูล
ทับทิมไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล Fixnumไม่มีข้อมูล Bignum
เออร์ลัง[น]ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล integer()ไม่มีข้อมูล integer()[o]
สกาล่าByteไม่มีข้อมูล ShortChar[ล]Intไม่มีข้อมูล Longไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล scala.math.BigInt
เมล็ดพันธุ์ 7ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล integerไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล bigInteger
การสนทนาเล็กๆ น้อยๆไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล SmallInteger[ฉัน]ไม่มีข้อมูล LargeInteger[ฉัน]
วินโดวส์ พาวเวอร์เชลล์ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล
โอแคมล์ไม่มีข้อมูล ไม่มีข้อมูล int32ไม่มีข้อมูล int64ไม่มีข้อมูล intหรือnativeintopen Big_int;;หรือbig_int
เอฟ#sbytebyteint16uint16int32หรือintuint32uint64nativeintunativeintbigint
มาตรฐาน MLไม่มีข้อมูล Word8.wordไม่มีข้อมูล Int32.intWord32.wordInt64.intWord64.wordintwordLargeInt.intหรือIntInf.int
ฮัสเคลล์ ( GHC ) «import Int»หรือInt8«import Word»หรือWord8«import Int»หรือInt16«import Word»หรือWord16«import Int»หรือInt32«import Word»หรือWord32«import Int»หรือInt64«import Word»หรือWord64Int«import Word»หรือWordInteger
หอไอเฟลINTEGER_8NATURAL_8INTEGER_16NATURAL_16INTEGER_32NATURAL_32INTEGER_64NATURAL_64INTEGERNATURALไม่มีข้อมูล
โคบอล[h]BINARY-CHAR «SIGNED»BINARY-CHAR UNSIGNEDBINARY-SHORT «SIGNED»BINARY-SHORT UNSIGNEDBINARY-LONG «SIGNED»BINARY-LONG UNSIGNEDBINARY-DOUBLE «SIGNED»BINARY-DOUBLE UNSIGNEDไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล
มาเทมาติกาไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล Integer
ภาษาวูลฟรามไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล ไม่มีข้อมูล Integer
  • ค่าคงที่มาตรฐานและint shortsสามารถint lengthsใช้เพื่อกำหนดจำนวนshorts และlongs ที่สามารถนำหน้าshort intและlong intขนาดจริงของshort int,int, และlong intมีให้ใช้งานในรูปของค่าคงที่short max int,max int, และlong max intเป็นต้น
  • ^bมักใช้สำหรับตัวอักษร
  • ภาษา ALGOL 68, C และ C++ ไม่ได้ระบุความกว้างที่แน่นอนของชนิดข้อมูลจำนวนเต็มshort,int,long, และ (C99,C++11)long longดังนั้นจึงขึ้นอยู่กับการใช้งาน ในภาษา C และ C++short,long, และlong longต้องมีความกว้างอย่างน้อย 16, 32 และ 64 บิต ตามลำดับ แต่สามารถมากกว่านั้นได้ ชนิดข้อมูลintต้องมีความกว้างอย่างน้อยเท่ากับshortและอย่างมากเท่ากับlongและโดยทั่วไปจะมีขนาดเท่ากับขนาดของเวิร์ดบนโปรเซสเซอร์ของเครื่อง (เช่น บนเครื่อง 32 บิต มักจะมีความกว้าง 32 บิต บนเครื่อง 64 บิต บางครั้งอาจมีความกว้าง 64 บิต)C99และC++11ยังกำหนด[u]intN_tชนิดข้อมูลที่มีความกว้างที่แน่นอนไว้ในstdint.hดูC syntax#Integral typesสำหรับข้อมูลเพิ่มเติม นอกจากนี้ ชนิดข้อมูลsize_tและptrdiff_tยังถูกกำหนดโดยสัมพันธ์กับขนาดของแอดเดรสเพื่อเก็บจำนวนเต็มที่ไม่มีเครื่องหมายและมีเครื่องหมายที่มีขนาดใหญ่พอที่จะจัดการกับดัชนีอาร์เรย์และความแตกต่างระหว่างพอยเตอร์ได้
  • ภาษา Perl 5 ไม่มีการแบ่งประเภทข้อมูลอย่างชัดเจน จำนวนเต็ม จำนวนทศนิยม สตริง ฯลฯ ล้วนถูกพิจารณาว่าเป็น "สเกลาร์"
  • PHPมีไลบรารีสำหรับการคำนวณค่าที่มีความแม่นยำสูงอยู่สองไลบรารี ไลบรารี BCMath ใช้สตริงเป็นชนิดข้อมูล ส่วนไลบรารี GMP ใช้ชนิดข้อมูลภายในที่เรียกว่า "resource"
  • ^fค่าของnถูกกำหนดโดยฟังก์ชันภายในSELECTED_INT_KIND [ 4 ]
  • ตัวเลือก รันไทม์ ของ ALGOL 68G--precision "number"สามารถตั้งค่าความแม่นยำสำหรับlong long ints เป็นจำนวนหลักสำคัญที่ต้องการได้ ค่าคงที่มาตรฐานlong long int widthและlong long max intสามารถใช้เพื่อกำหนดความแม่นยำที่แท้จริงได้
  • ภาษา COBOLอนุญาตให้ระบุความแม่นยำที่ต้องการ และจะเลือกชนิดข้อมูลที่พร้อมใช้งานซึ่งสามารถแสดงความแม่นยำที่ระบุได้โดยอัตโนมัติPIC S9999ตัวอย่างเช่น จะต้องใช้ตัวแปรแบบมีเครื่องหมายที่มีความแม่นยำสี่หลักทศนิยม หากระบุเป็นฟิลด์ไบนารี ระบบจะเลือกชนิดข้อมูลแบบมีเครื่องหมาย 16 บิตบนแพลตฟอร์มส่วนใหญ่
  • Smalltalk จะเลือกวิธีการแสดงจำนวนเต็มที่เหมาะสมโดยอัตโนมัติ โดยทั่วไปจะมีสองรูปแบบ รูปแบบหนึ่งสำหรับจำนวนเต็มที่พอดีกับขนาดเวิร์ดดั้งเดิมลบด้วยบิตแท็ก (SmallInteger) และอีกรูปแบบหนึ่งสำหรับจำนวนเต็มที่มีขนาดตามต้องการ (LargeInteger)การดำเนินการทางคณิตศาสตร์รองรับอาร์กิวเมนต์แบบโพลีมอร์ฟิกและส่งคืนผลลัพธ์ในรูปแบบที่กระชับที่สุดที่เหมาะสมที่สุด
  • ^j ประเภทช่วง ของ Adaจะถูกตรวจสอบการละเมิดขอบเขตในขณะรันไทม์ (รวมถึงในขณะคอมไพล์สำหรับนิพจน์แบบคงที่) การละเมิดขอบเขตในขณะรันไทม์จะทำให้เกิดข้อยกเว้น "ข้อผิดพลาดข้อจำกัด" ช่วงไม่ได้จำกัดเฉพาะกำลังของสอง ประเภทย่อยของจำนวนเต็มที่กำหนดไว้ล่วงหน้าโดยทั่วไป ได้แก่ จำนวนเต็มบวก () และจำนวนเต็มธรรมชาติ ()(8 บิต),(16 บิต) และ(64 บิต) ก็ถูกกำหนดไว้ล่วงหน้าโดยทั่วไปเช่นกัน แต่ไม่ได้เป็นข้อกำหนดตามมาตรฐาน Ada การตรวจสอบในขณะรันไทม์สามารถปิดใช้งานได้หากประสิทธิภาพมีความสำคัญมากกว่าการตรวจสอบความสมบูรณ์range1..Integer'Lastrange0..Integer'LastShort_Short_IntegerShort_IntegerLong_Integer
  • ^k ประเภทโมดูลัส ของ Adaใช้การคำนวณโมดูลัสในทุกการดำเนินการ กล่าวคือ จะไม่มีการละเมิดช่วงเกิดขึ้น โมดูลัสไม่ได้จำกัดเฉพาะกำลังของสองเท่านั้น
  • ^lมักใช้สำหรับอักขระเช่น char ในภาษา Java
  • ^mintใน PHP มีความกว้างเท่ากับlongtype ใน C บนระบบนั้น [c]
  • ^n Erlangเป็นภาษาที่มีการกำหนดประเภทแบบไดนามิก ตัวระบุประเภทมักใช้เพื่อระบุประเภทของฟิลด์เรคอร์ดและประเภทของอาร์กิวเมนต์และค่าส่งคืนของฟังก์ชัน [ 5 ]
  • ^oเมื่อเกินหนึ่งคำ [ 6 ]
ความแม่นยำเดี่ยวความแม่นยำสองเท่าความแม่นยำอื่นๆ ขึ้นอยู่กับโปรเซสเซอร์
อาดา[ 1 ]FloatLong_Floatไม่มีข้อมูล
อัลโกล 68real[ก]long real[ก]short real, long long real, เป็นต้น[ง]
ซีfloat[ข]doublelong double[f]
ซี++ (STL)
ออบเจกทีฟซี ( โกโก้ ) CGFloat
ซี#floatไม่มีข้อมูล
คริสตัลFloat64Float64
ชวาfloatdouble
ไปfloat32float64ไม่มีข้อมูล
สนิมf32f64f16, f128
สวิฟต์FloatหรือFloat32DoubleหรือFloat64Float80[ก]CGFloat
ดีfloatdoublereal
ลิสปาร์กทั่วไปsingle-floatdouble-floatfloat, short-float, long-float
โครงการ
ไอเอสลิสป์
ปาสคาล ( FPC ) singledoublereal
วิชวลเบสSingleDoubleไม่มีข้อมูล
Visual Basic .NET
โซโจ
ไพธอนไม่มีข้อมูลfloat
โค้ด JavaScriptNumber[ 7 ]ไม่มีข้อมูล
เอส-ลัง
ฟอร์ทรานREAL(KIND = n)[ค]
พีพีfloat
เพิร์ล
ราคุnum32num64Num
ทับทิมไม่มีข้อมูลFloatไม่มีข้อมูล
สกาล่าFloatDouble
เมล็ดพันธุ์ 7ไม่มีข้อมูลfloat
การสนทนาเล็กๆ น้อยๆFloatDouble
วินโดวส์ พาวเวอร์เชลล์
โอแคมล์ไม่มีข้อมูลfloatไม่มีข้อมูล
เอฟ#float32
มาตรฐาน MLไม่มีข้อมูลreal
ฮัสเคลล์ ( GHC ) FloatDouble
หอไอเฟลREAL_32REAL_64
โคบอลFLOAT-BINARY-7[e]FLOAT-BINARY-34[e]FLOAT-SHORT, FLOAT-LONG,FLOAT-EXTENDED
มาเทมาติกาไม่มีข้อมูลไม่มีข้อมูลReal
  • ค่าคงที่มาตรฐานและreal shortsสามารถreal lengthsใช้เพื่อกำหนดจำนวนshorts และlongs ที่สามารถนำหน้าshort realและได้long realขนาดจริงของshort real,real, และlong realมีให้ใช้งานในรูปของค่าคงที่short max real,max realและlong max realเป็นต้น โดยมีค่าคงที่short small real,small realและลอนเครื่องlong small realแต่ละประเภท
  • การประกาศ ค่าความแม่นยำเดี่ยว (single precision) มักจะไม่ได้รับการยอมรับ
  • ^cค่าของnถูกกำหนดโดยฟังก์ชันภายในSELECTED_REAL_KIND [ 8 ]
  • ตัวเลือกรันไทม์ของ ALGOL 68G--precision "number"สามารถตั้งค่าความแม่นยำสำหรับlong long reals ให้เป็นจำนวนหลักสำคัญที่ต้องการได้ ค่าคงที่มาตรฐานlong long real widthและlong long max realสามารถใช้เพื่อกำหนดความแม่นยำที่แท้จริงได้
  • ^e ประเภทข้อมูลจุดลอยตัว ของ IEEEเหล่านี้จะถูกนำมาใช้ในมาตรฐาน COBOL รุ่นต่อไป
  • ^fขนาดเท่ากับที่doubleใช้ในหลายๆ การใช้งาน
  • ^g Swift รองรับชนิดข้อมูลจุดลอยตัว ความแม่นยำสูง80 บิตซึ่งเทียบเท่ากับlong doubleในภาษา C
จำนวนเต็ม ความแม่นยำเดี่ยว ความแม่นยำสองเท่า ความแม่นยำครึ่งและสี่เท่า เป็นต้น
อาดา[ 1 ]ไม่มีข้อมูลComplex[ข]Complex[ข]Complex[ข]
อัลโกล 68ไม่มีข้อมูลcompllong complเป็นต้น short complเป็นต้น และlong long complอื่นๆ
C ( C99 ) [ 9 ]ไม่มีข้อมูลfloat complexdouble complexไม่มีข้อมูล
ซี++ (STL) ไม่มีข้อมูลstd::complex<float>std::complex<double>
ซี#ไม่มีข้อมูลไม่มีข้อมูลSystem.Numerics.Complex(.NET 4.0)
ชวาไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
ไปไม่มีข้อมูลcomplex64complex128
ดีไม่มีข้อมูลcfloatcdouble
ออบเจกทีฟซีไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
ลิสปาร์กทั่วไป(จำนวนเต็มเชิงซ้อน) (ค่าลอยตัวเดี่ยวที่ซับซ้อน) (ค่าลอยตัวคู่ที่ซับซ้อน) ซับซ้อน
โครงการไม่มีข้อมูล
ปาสคาลไม่มีข้อมูลไม่มีข้อมูล
วิชวลเบสไม่มีข้อมูลไม่มีข้อมูล
Visual Basic .NETไม่มีข้อมูลไม่มีข้อมูลSystem.Numerics.Complex(.NET 4.0)
เพิร์ลMath::Complex
ราคุcomplex64complex128Complex
ไพธอนcomplexไม่มีข้อมูล
โค้ด JavaScriptไม่มีข้อมูลไม่มีข้อมูล
เอส-ลังไม่มีข้อมูลไม่มีข้อมูล
ฟอร์ทรานCOMPLEX(KIND = n)[ก]
ทับทิมComplexไม่มีข้อมูลComplex
สกาล่าไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
เมล็ดพันธุ์ 7ไม่มีข้อมูลไม่มีข้อมูลcomplex
การสนทนาเล็กๆ น้อยๆComplexComplexComplex
วินโดวส์ พาวเวอร์เชลล์ไม่มีข้อมูลไม่มีข้อมูล
โอแคมล์ไม่มีข้อมูลไม่มีข้อมูลComplex.t
เอฟ#System.Numerics.Complex(.NET 4.0)
มาตรฐาน MLไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
ฮัสเคลล์ ( GHC ) ไม่มีข้อมูลComplex.Complex FloatComplex.Complex Double
หอไอเฟลไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
โคบอลไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
มาเทมาติกาComplexไม่มีข้อมูลไม่มีข้อมูลComplex
  • ^aค่าของnถูกกำหนดโดยฟังก์ชันภายในSELECTED_REAL_KIND [ 8 ]
  • ^bชนิดข้อมูลทั่วไปที่สามารถสร้างอินสแตนซ์ได้ด้วยชนิดข้อมูลจุดลอยตัวพื้นฐานใดๆ ก็ได้

ประเภทตัวแปรอื่นๆ

ข้อความ บูลีนการนับจำนวนวัตถุ / สากล
อักขระสตริง[a]
อาดา[ 1 ]CharacterString, Bounded_String,Unbounded_StringBoolean(item1, item2, ...)tagged null record
อัลโกล 68charstring,bytesbool,bitsไม่มีข้อมูล - กำหนดโดยผู้ใช้ไม่มีข้อมูล
ซี ( ซี99 ) char,wchar_tไม่มีข้อมูล bool[ข]enum «name» { item1, item2, ... };void*
ซี++ (STL) «std::»string
ออบเจกทีฟซีunicharNSString *BOOLid
ซี#charstringboolenum name { item1« = value», item2« = value», ... }วัตถุ
คริสตัลCharStringBoolenum Name item1item2...endไม่มีข้อมูล
ชวาcharbooleanenum name { item1, item2, ... }Object
ไปbyte,runestringboolconst (   item1 = iota   item2   ...)interface{}
สนิมcharStringboolenum name { item1« = value», item2« = value», ... }std::any::Any
สวิฟต์CharacterStringBoolenum name { case item1, item2, ... }Any
ดีcharstringboolenum name { item1, item2, ... }std.variant.Variant
ลิสปาร์กทั่วไปcharacterstringboolean(member item1item2...)t
โครงการ
ไอเอสลิสป์
ปาสคาล (ISO) charไม่มีข้อมูล boolean( item1, item2, ... )ไม่มีข้อมูล
ออบเจ็กต์ปาสคาล ( เดลฟี ) stringvariant
วิชวลเบสไม่มีข้อมูล StringBooleanEnum name   item1 «= value»   item2 «= value»   ...End EnumVariant
Visual Basic .NETCharObject
โซโจไม่มีข้อมูล ObjectหรือVariant
ไพธอนไม่มีข้อมูล[d]strbool
fromenumimportEnumclassName(Enum):รายการที่1 = มูลค่ารายการที่ 2 = มูลค่า...
object
โค้ด JavaScriptไม่มีข้อมูล[d]StringBooleanObject
เอส-ลัง
ฟอร์ทรานCHARACTER(LEN=*)CHARACTER(LEN=:),allocatableLOGICAL(KIND=n)[f]CLASS(*)
พีพีไม่มีข้อมูล[d]stringbool(ละการประกาศประเภท)
เพิร์ลไม่มีข้อมูล[d]UNIVERSAL
ราคุCharStrBoolenum name<item1 item2 ...>enum name «:item1(value) :item2(value) ..»Mu
ทับทิมไม่มีข้อมูล[d]StringObject[ค]Object
สกาล่าCharStringBooleanobject name extends Enumeration {   val item1, item2, ... = Value}Any
เมล็ดพันธุ์ 7charstringbooleanconst type: name is new enum   item1,   item2,   ...end enum;
วินโดวส์ พาวเวอร์เชลล์
โอแคมล์charstringboolไม่มีข้อมูล[e]ไม่มีข้อมูล
เอฟ#type name = item1 = value |item2 = value | ...obj
มาตรฐาน MLไม่มีข้อมูล[e]ไม่มีข้อมูล
ฮัสเคลล์ ( GHC ) CharStringBoolไม่มีข้อมูล[e]ไม่มีข้อมูล
หอไอเฟลCHARACTERSTRINGBOOLEANไม่มีข้อมูล ANY
โคบอลPIC XPIC X(string length)หรือPIC X«X...»PIC 1«(number of digitsหรือPIC 1«1...»ไม่มีข้อมูล OBJECT REFERENCE
มาเทมาติกาไม่มีข้อมูล[d]Stringไม่มีข้อมูล
  • โดยเฉพาะอย่างยิ่ง สตริงที่มีความยาวไม่จำกัดและได้รับการจัดการโดยอัตโนมัติ
  • ^bภาษาโปรแกรมนี้แสดงค่าบูลีนเป็นจำนวนเต็ม โดยค่าเท็จแทนด้วยค่าศูนย์ และค่าจริงแทนด้วยค่าที่ไม่ใช่ศูนย์
  • ค่าทั้งหมดใน ^cจะประเมินได้เป็นจริงหรือเท็จ ทุกอย่างในTrueClassจะมีค่าเป็นจริง และทุกอย่างในFalseClassจะมีค่าเป็นเท็จ
  • ภาษานี้ไม่มีประเภทอักขระแยกต่างหาก อักขระจะถูกแทนด้วยสตริงที่มีความยาว 1
  • การ แจงนับในภาษานี้เป็นประเภทพีชคณิตที่มีตัวสร้างที่เป็นค่าว่างเท่านั้น
  • ^fค่าของnถูกกำหนดโดยฟังก์ชันภายในSELECTED_INT_KIND [ 4 ]

ประเภทที่ได้มา

อาร์เรย์ขนาดคงที่ อาร์เรย์ขนาดไดนามิก
อาร์เรย์หนึ่งมิติอาร์เรย์หลายมิติอาร์เรย์หนึ่งมิติอาร์เรย์หลายมิติ
อาดา[ 1 ]array (<first> .. <last>) of <type>หรือarray (<discrete_type>) of <type>array (<first1> .. <last1>, <first2> .. <last2>, ...) of <type>หรือarray (<discrete_type1>, <discrete_type2>, ...) of <type>array (<discrete_type> range <>) of <type>array (<discrete_type1> range <>, <discrete_type2> range <>, ...) of <type>
อัลโกล 68[first:last]«modename»หรือพูดง่ายๆ ก็คือ:[size]«modename»[first1:last1, first2:last2]«modename»หรืออื่นๆ [first1:last1][first2:last2]«modename»flex[first:last]«modename»หรือพูดง่ายๆ ก็คือ:flex[size]«modename»flex[first1:last1, first2:last2]«modename»หรือflex[first1:last1]flex[first2:last2]«modename» etc.
ซี ( ซี99 ) type name[size][ก]type name[size1][size2][ก]type *nameหรือภายในบล็อก:int n = ...; type name[n]
ซี++ (STL) «std::»array<type, size>(ซี++11) «std::»vector<type>
ซี#type[]type[,,...]System.Collections.ArrayListหรือSystem.Collections.Generic.List<type>
คริสตัลArray(type[s]).new(size)[ข]Array(type[s]).new
ชวาtype[][ค]type[][]...[ค]ArrayList or ArrayList<type>
ดีtype[size]type[size1][size2]type[]
ไป[size]type[size1][size2]...type[]type[][]type
สนิม[type; size][[type; size1]; size2]Vec<type>Vec<Vec<type>>
สวิฟต์[type]หรือArray<type>[[type]]หรือArray<Array<type>>
ออบเจกทีฟซีNSArrayNSMutableArray
โค้ด JavaScriptไม่มีข้อมูลไม่มีข้อมูลArray[ง]
ลิสปาร์กทั่วไป(simple-arraytype(dimension))(simple-arraytype(dimension1dimension2))(arraytype(dimension))(arraytype(dimension1dimension2))
โครงการ
ไอเอสลิสป์
ปาสคาลarray[first..last] of type[e]array[first1..last1] of array[first2..last2] ... of type[e]หรือ [e] array[first1..last1, first2..last2, ...] of typeไม่มีข้อมูลไม่มีข้อมูล
ออบเจ็กต์ปาสคาล ( เดลฟี ) array of typearray of array ... of type
วิชวลเบสDim x(last) As typeDim x(last1, last2,...) As type
Visual Basic .NETtype()type(,,...)System.Collections.ArrayListหรือSystem.Collections.Generic.List(Of type)
ไพธอนlist
เอส-ลังx = type[size];x = type[size1, size2, ...];
ฟอร์ทรานtype :: name(size)type :: name(size1, size2,...)type, ALLOCATABLE :: name(:)type, ALLOCATABLE :: name(:,:,...)
พีพีarray
เพิร์ล
ราคุArray[type] or Array of type
ทับทิมx = Array.new(size1){ Array.new(size2) }Array
สกาล่าArray[type]Array[...[Array[type]]...]ArrayBuffer[type]
เมล็ดพันธุ์ 7array typeหรือarray [idxType] typearray array typeหรือarray [idxType] array [idxType] typearray typeหรือarray [idxType] typearray array typeหรือarray [idxType] array [idxType] type
การสนทนาเล็กๆ น้อยๆArrayOrderedCollection
วินโดวส์ พาวเวอร์เชลล์type[]type[,,...]
โอแคมล์type arraytype array ... array
เอฟ#type []หรือtype arraytype [,,...]System.Collections.ArrayListหรือSystem.Collections.Generic.List<type>
มาตรฐาน MLtype vector or type array
ฮัสเคลล์ ( GHC ) x=Array.array(0,size-1) list_of_association_pairsx=Array.array((0,0,...), (size1-1, size2-1,...)) list_of_association_pairs
โคบอลlevel-number type OCCURS size «TIMES».นิยามของอาร์เรย์หนึ่งมิติ...level-number type OCCURS min-size TO max-size«TIMES»DEPENDING «ON»size.[f]ไม่มีข้อมูล
  • ^aในนิพจน์ส่วนใหญ่ (ยกเว้นsizeofand&) ค่าของชนิดอาร์เรย์ในภาษา C จะถูกแปลงเป็นตัวชี้ไปยังอาร์กิวเมนต์แรกโดยอัตโนมัติ ดูรายละเอียดเพิ่มเติมเกี่ยวกับไวยากรณ์และการดำเนินการกับตัวชี้ได้ที่ C syntax#Arrays
  • เนื่องจากชนิดข้อมูลทั้งหมดใน Crystal เป็นอ็อบเจ็กต์ ดังนั้นอาร์เรย์จึงสามารถบรรจุอาร์เรย์อื่นได้โดยธรรมชาติ โดยการระบุไว้ในค่าคงที่หรือการประกาศชนิดข้อมูล (เช่นArray(Array(Int32 | Float64))ระบุอาร์เรย์สองมิติที่ประกอบด้วยจำนวนเต็ม 32 บิตและจำนวนทศนิยมความแม่นยำสูง)
  • ^c รูป แบบที่คล้ายกับภาษา Ctype x[]สามารถใช้งานได้ใน Java แต่type[] xเป็นรูปแบบการประกาศอาร์เรย์ที่นิยมมากกว่า
  • ช่วงย่อยใช้เพื่อกำหนดขอบเขตของอาร์เรย์
  • อาร์เรย์ใน JavaScriptเป็นวัตถุชนิดพิเศษ
  • ^fเงื่อนไขDEPENDING ONใน COBOL ไม่ได้สร้างได้จริงและจะจัดสรรขนาดสูงสุดของอาร์เรย์เสมอ

ประเภทอื่นๆ

ประเภทคอมโพสิตแบบง่าย ประเภทข้อมูลเชิงพีชคณิตสหภาพแรงงาน
บันทึกการแสดงออกของ ทูเพิล
อาดา[ 1 ]type name is «abstract» «tagged» «limited» [record  field1 : type;  field2 : type;  ...end record | null record]ไม่มีข้อมูล การรวมกันใดๆ ของเรคอร์ด ยูเนียน และการแจงนับ (รวมถึงการอ้างอิงถึงสิ่งเหล่านั้น ซึ่งช่วยให้สามารถสร้างประเภทแบบเรียกซ้ำได้) type name (variation : discrete_type) is record  case variation is   when choice_list1 =>    fieldname1 : type;    ...   when choice_list2 =>    fieldname2 : type;    ...   ...  end case;end record
อัลโกล 68struct (modename «fieldname», ...);ประเภทและตัวดำเนินการที่จำเป็นสามารถกำหนดเองได้โดยผู้ใช้union (modename, ...);
ซี ( ซี99 ) struct «name» {type name;...};ไม่มีข้อมูล ไม่มีข้อมูล union {type name;...};
ออบเจกทีฟซี
ซี++struct «name» {type name;...};[ข]«std::»tuple<type1..typen>
ซี#struct name {type name;...}(val1, val2, ... )ไม่มีข้อมูล
คริสตัลclass Name  def initialize(name : type)   @name = name  endend{val1, val2, ...}classes และstructs สามารถใช้เพื่อกำหนดการผสมผสานของประเภทต่างๆ และการดำเนินการใดๆ กับประเภทเหล่านั้นผ่านทางเมธอดของพวกมันได้
ชวาไม่มีข้อมูล[ก]
โค้ด JavaScriptไม่มีข้อมูล
ดีstruct name {type name;...}std.variant.Algebraic!(type,...)union {type name;...}
ไปstruct {   «name» type  ...}
สนิมstruct name {name: type, ...}(val1, val2, ... )enum name { Foo(types), ...}union name {name: type, ...}
สวิฟต์struct name {  var name «: type»  ...}(«name1:» val1, «name2:» val2, «name3:» val3, ... )enum name { case Foo«(types)» case Bar «(types... }
ลิสปาร์กทั่วไป(defstructnameslot-name(slot-nameinitial-value)(slot-nameinitial-value:typetype)...)(cons val1 val2)[ค]
โครงการไม่มีข้อมูล
ไอเอสลิสป์
ปาสคาลrecord  name: type;  ...endไม่มีข้อมูล ไม่มีข้อมูล record  case type of  value: (types);  ...end
วิชวลเบส
Visual Basic .NETStructure name  Dim name As type  ...End Structure(val1, val2, ... )
ไพธอนไม่มีข้อมูล[ก]«(»val1, val2, val3, ... «)»ไม่มีข้อมูล
เอส-ลังstruct {name [=value], ...}
ฟอร์ทรานTYPE name  type :: name  ...END TYPE
พีพีไม่มีข้อมูล[ก]
เพิร์ลไม่มีข้อมูล[d]ไม่มีข้อมูล
ราคุไม่มีข้อมูล[ก]
ทับทิมOpenStruct.new({:name=>value})
สกาล่าcase class namevar» name: type, ...)(val1, val2, val3, ... )abstract class name  case class Fooparameters») extends name  case class Barparameters») extends name  ...หรือการผสมผสานระหว่างคลาสเคสและออบเจ็กต์เคส abstract class name  case object Foo extends name  case object Bar extends name  ...
วินโดวส์ พาวเวอร์เชลล์
โอแคมล์type name = {«mutable» name : type;...}«(»val1, val2, val3, ... «)»type name = Foo «of type» | Bar «of type» | ...ไม่มีข้อมูล
เอฟ#
มาตรฐาน MLtype name = {name : type,...}(val1, val2, val3, ... )datatype name = Foo «of type» | Bar «of type» | ...
ฮัสเคลล์data Name = Constr {name :: type,...}data Name = Foo «types» | Bar «types» | ...
โคบอลlevel-numbernametypeclauses.  level-number+nnametypeclauses.  ...ไม่มีข้อมูล ไม่มีข้อมูล name REDEFINES variable type.
  • ^aรองรับเฉพาะคลาสเท่านั้น
  • ใน C++ นั้น ^bstructก็คือคลาส แต่โดยค่าเริ่มต้นจะมีระดับการมองเห็นเป็น public และเป็นPODด้วยเช่นกันC++11 ได้ขยายขอบเขตนี้เพิ่มเติม ทำให้คลาสทำงานเหมือนกับอ็อบเจ็กต์ POD ในหลายกรณีมากขึ้น
  • คู่ ^cเท่านั้น
  • แม้ว่า Perl จะไม่มีเรคอร์ด แต่เนื่องจากระบบประเภทข้อมูลของ Perl อนุญาตให้มีข้อมูลประเภทต่างๆ อยู่ในอาร์เรย์ได้ ดังนั้น "แฮช" (อาร์เรย์แบบเชื่อมโยง) ที่ไม่มีดัชนีตัวแปรจึงมีผลเหมือนกับเรคอร์ด
  • การ แจงนับในภาษานี้เป็นประเภทพีชคณิตที่มีตัวสร้างที่เป็นค่าว่างเท่านั้น

การประกาศตัวแปรและค่าคงที่

ตัวแปร คงที่ ประเภทคำพ้องความหมาย
อาดา[ 1 ]identifier : type« := initial_value»[e]identifier : constant type := final_valuesubtype identifier is type
อัลโกล 68modename name« := initial_value»;modename name = value;mode synonym = modename;
ซี ( ซี99 ) type name« = initial_value»;enum{ name = value };typedeftype synonym;
ออบเจกทีฟซี
ซี++const type name = value;
ซี#type name1« = initial_value», name2« = initial_value», ...;หรือvar name = initial_value;const type name = value, name = value, ...;หรือreadonly type name = value, name = value, ... ;using synonym = type;
คริสตัลname : type = initial_valueหรือname = initial_valueNAME = valuealias synonym = type
ดีtype name« = initial_value»;หรือauto name = value;const type name = value;หรือimmutable type name = value;alias type synonym;
ชวาtype name« = initial_value»;final type name = value;ไม่มีข้อมูล
โค้ด JavaScriptvar name« = initial_value»;หรือ(ตั้งแต่ECMAScript 2015) let name« = initial_value»;const name = value;(ตั้งแต่ECMAScript 2015)
ไปvar name type« = initial_value»หรือname := initial_valueconst name «type» = valuetype synonym type
แร็กเก็ต(define name expression)
สนิม[f]let mut name«: type»« = initial_value»;static mut NAME: type = value;let name«: type»« = initial_value»;const NAME: type = value;static NAME: type = value;type synonym = typename;
สวิฟต์var name «: type»« = initial_value»let name «: type» = valuetypealias synonym = type
ลิสปาร์กทั่วไป(defparameter name initial-value)หรือ(defvar name initial-value)(defconstant name value)(deftype synonym () 'type)
โครงการ(define name initial_value)
ไอเอสลิสป์(defglobal name initial_value)หรือ(defdynamic name initial_value)(defconstant name value)ไม่มีข้อมูล
ปาสคาล[a]name: type« = initial_value»name = valuesynonym = type
วิชวลเบสDim name «As type»ดูหมายเหตุทางด้านซ้าย

ค่าคงที่ใช้ไวยากรณ์เดียวกัน และ:

  • ใช้ConstแทนDim
  • มีข้อจำกัดเฉพาะประเภทพื้นฐานบางประเภทเท่านั้นConst name1 «As type» = value, name2 «As type» = value, ...
Visual Basic .NET [ 10 ]ไวยากรณ์การประกาศตัวแปรของ VB.NET นั้นยากที่จะอธิบายอย่างแม่นยำเป็นพิเศษ

เนื่องจากมีคำต่อท้ายระบุตัวตน ("ตัวดัดแปลง") อยู่:

  • type_characterสามารถใช้เป็นทางเลือกแทนAsข้อกำหนดสำหรับชนิดข้อมูลพื้นฐานบางประเภทได้
  • nullable_specifier; และ
  • array_specifier;

และนั่น

  • a modified_identifierมีรูปแบบดังนี้identifier«type_character»«nullable_specifier»«array_specifier»;
  • a modified_identifier_listคือรายการที่คั่นด้วยเครื่องหมายจุลภาคซึ่งประกอบด้วยเครื่องหมาย ; สองตัวขึ้นไปmodified_identifierและ
  • a declarator_listคือรายการตัวประกาศที่คั่นด้วยเครื่องหมายจุลภาค ซึ่งอาจอยู่ในรูปแบบ
    • identifier As object_creation_expression(ตัวประกาศเริ่มต้นวัตถุ )
    • modified_identifier «As non_array_type«array_rank_specifier»»« = initial_value»(ตัวประกาศเดียว)หรือ
    • modified_identifier_list «As «non_array_type««array_rank_specifier»»(ตัวประกาศหลายตัว);

ข้อความประกาศที่ถูกต้องจะมีรูปแบบ       โดยที่ เพื่อวัตถุประสงค์ในการวิเคราะห์ความหมาย จะต้องแปลงให้เป็นรายการของผู้ประกาศเพียงรายเดียว: Dim declarator_listdeclarator_list

  • ข้อความAsของแต่ละผู้ประกาศหลายรายการจะถูกกระจายไปทั่วข้อความนั้นmodified_identifier_list
  • ตัวประกาศเริ่มต้น ของแต่ละอ็อบเจ็กต์จะถูกแทนที่ด้วยAs New type...As type = New type...

และสำหรับสิ่งเหล่านั้น สำหรับแต่ละidentifierสิ่ง

  • a type_characterและAsclause ไม่ปรากฏพร้อมกัน
  • หากAsมีข้อความดังกล่าวอยู่
    • คำ ว่า "an" array_rank_specifierไม่ปรากฏทั้งในรูปแบบการแก้ไขตัวระบุและในประเภทของAsข้อความ
  • สามารถกำหนด an unmodified_typeได้โดยใช้กฎที่ว่า
    • หากมี เงื่อนไข type_characterหรือAsข้อความอยู่
      • unmodified_typeคือสิ่งที่ระบุไว้โดยโครงสร้างดังกล่าว
    • และมิเช่นนั้น
      • Option Inferจะต้องเปิดใช้งานอย่างใดอย่างหนึ่ง และจะ identifierต้องมีตัวเริ่มต้น ซึ่งในกรณีนี้unmodified_typeจะเป็นตัวเริ่มต้น หรือ
      • Option Strictจะต้องปิดอยู่ ซึ่งในกรณีนี้unmodified_typeคือObject;
  • its final_typeคือคำunmodified_typeที่นำหน้าคำขยาย its
  • เป็นfinal_typeประเภทที่ถูกต้อง และ
  • หากinitial_valueมีอยู่
    • อันใดอันหนึ่งOption Strictเปิดอยู่และinitial_valueมีการแปลงที่กว้างขึ้นเป็นfinal_typeหรือ
    • Option Strictปิดอยู่และinitial_valueมีการแปลงที่แคบลงเป็นfinal_type.

หากOption Explicitปิดใช้งานอยู่ ตัวแปรไม่จำเป็นต้องประกาศอย่างชัดเจน ตัวแปรจะถูกประกาศโดยปริยายเมื่อถูกใช้งาน: name=initial_value

Imports synonym = type
โซโจDim name «As type»« = initial_value»ไม่มีข้อมูล
ไพธอนname«: type» = initial_valueไม่มีข้อมูลsynonym = type[ข]
คอฟฟี่สคริปต์name = initial_value
เอส-ลังname = initial_value;typedef struct {...} typename
ฟอร์ทรานtype :: nametype, PARAMETER :: name = value
พีพี$name = initial_value;define("name", value);const name = value (5.3+)ไม่มีข้อมูล
เพิร์ล«my» $name« = initial_value»;[ค]use constant name => value;
ราคุ«my «type»» $name« = initial_value»;[ค]«my «type»» constant name = value;::synonym ::= type
ทับทิมname = initial_valueName = valuesynonym = type[ข]
สกาล่าvar name«: type» = initial_valueval name«: type» = valuetype synonym = type
วินโดวส์ พาวเวอร์เชลล์«[type]» $name = initial_valueไม่มีข้อมูลไม่มีข้อมูล
เปลือกหอยname=initial_valueไม่มีข้อมูลไม่มีข้อมูล
โอแคมล์let name« : type ref» = ref value[ง]let name «: type» = valuetype synonym = type
เอฟ#let mutable name «: type» = value
มาตรฐาน MLval name «: type ref» = ref value[ง]val name «: type» = value
ฮัสเคลล์«name::typename = valuetype Synonym = type
ไปข้างหน้าVARIABLE name(ในบางระบบให้ใช้แทน) value VARIABLE namevalue CONSTANT name
โคบอลlevel-number name type clauses.«0»1 name CONSTANT «AS» value.level-number name type clauses «IS» TYPEDEF.
มาเทมาติกาname=initial_valueไม่มีข้อมูลไม่มีข้อมูล
  • ภาษาปาสคาลมีบล็อกการประกาศ ดูที่ฟังก์ชัน
  • ^bประเภทต่างๆ ก็เป็นเพียงวัตถุทั่วไป ดังนั้นคุณสามารถกำหนดค่าให้กับมันได้เลย
  • ใน ภาษา Perl คำหลัก "my" จะกำหนดขอบเขตของตัวแปรให้อยู่ภายในบล็อก
  • ในทางเทคนิคแล้ว คำสั่งนี้ไม่ได้ประกาศnameเป็นตัวแปรที่เปลี่ยนแปลงได้—ใน ML นั้น name ทุกตัวสามารถผูกได้เพียงครั้งเดียวเท่านั้น—แต่เป็นการประกาศnameชี้ไปยังโครงสร้างข้อมูล "อ้างอิง" ซึ่งเป็นเซลล์ที่เปลี่ยนแปลงได้ง่ายๆ โครงสร้างข้อมูลนี้สามารถอ่านและเขียนได้โดยใช้!และ:=ตามลำดับ
  • ^eหากไม่ได้ระบุค่าเริ่มต้น ระบบจะกำหนดค่าที่ไม่ถูกต้องให้โดยอัตโนมัติ (ซึ่งจะทำให้เกิดข้อผิดพลาดขณะรันไทม์หากใช้ก่อนที่จะมีการกำหนดค่าที่ถูกต้อง) แม้ว่าพฤติกรรมนี้จะสามารถระงับได้ แต่ขอแนะนำให้ระงับเพื่อความคาดเดาได้ หากไม่พบค่าที่ไม่ถูกต้องสำหรับประเภทข้อมูล (เช่น ในกรณีของประเภทจำนวนเต็มที่ไม่จำกัด) ระบบจะเลือกค่าที่ถูกต้องแต่คาดเดาได้แทน
  • ใน Rustหากไม่มีการกำหนดค่าเริ่มต้นให้กับletหรือ `let mutglobal` และไม่เคยมีการกำหนดค่าให้กับตัวแปรนั้นในภายหลัง จะมีคำเตือน "ตัวแปรไม่ได้ใช้งาน"หากไม่มีการระบุค่าให้กับconstหรือstaticหรือ `static mutglobal` จะเกิดข้อผิดพลาด นอกจากนี้ยังมี"ตัวแปรส่วนกลางที่ไม่ใช่ตัวพิมพ์ใหญ่"สำหรับตัวแปรที่ไม่ใช่ตัวพิมพ์ใหญ่constหลังจากที่กำหนดตัวแปรแล้วstatic mutจะสามารถกำหนดค่าให้กับตัวแปรได้เฉพาะในunsafeบล็อกหรือฟังก์ชัน

ประโยคเงื่อนไข

ถ้า มิฉะนั้นถ้า เลือกกรณีนิพจน์เงื่อนไข
อาดา[ 1 ]if condition then  statements«else  statements»end ifif condition1 then  statementselsif condition2 then  statements...«else  statements»end ifcase expression is  when value_list1 => statements  when value_list2 => statements  ...  «when others => statements»end case(if condition1 then  expression1«elsif condition2 then  expression2»...else  expressionn)หรือ(case expression is  when value_list1 => expression1  when value_list2 => expression2  ...  «when others => expressionn»)
เมล็ดพันธุ์ 7if condition then  statements«else  statements»end ifif condition1 then  statementselsif condition2 then  statements...«else  statements»end ifcase expression of  when set1 : statements  ...  «otherwise: statements»end case
โมดูลา-2if condition then  statements«else  statements»endif condition1 then  statementselsif condition2 then  statements...«else  statements»endcase expression of  caseLabelList : statements |  ...  «else statements»end
อัลโกล 68if condition then statements «else statements» fiif condition then statements elif condition then statements ficase switch in statements, statements«,... out statements» esac( condition | valueIfTrue | valueIfFalse )
ALGOL 68 (ฉบับย่อ) ( condition | statements «| statements» )( condition | statements |: condition | statements )( variable | statements,... «| statements» )
เอพีแอล:If condition  instructions«:Else  instructions»:EndIf:If condition  instructions:ElseIf condition  instructions...«:Else  instructions»:EndIf:Select expression  :Case case1   instructions  ...  «:Else   instructions»:EndSelect{condition:valueIfTruevalueIfFalse}
ซี ( ซี99 ) if (condition) instructions«else instructions»instructionsอาจเป็นข้อความเดียวหรือเป็นกลุ่มข้อความในรูปแบบ:{ statements }if (condition) instructionselse if (condition) instructions...«else instructions»หรือif (condition) instructionselse { if (condition) instructions }switch (variable) {   case case1: instructions «; break;»  ...  «default: instructions»}condition?valueIfTrue:valueIfFalse
ออบเจกทีฟซี
ซี++ (STL)
ดี
ชวา
โค้ด JavaScript
พีพี
ซี#if (condition) instructions«else instructions»

instructionsอาจเป็นข้อความเดียวหรือเป็นกลุ่มข้อความในรูปแบบ:{ statements }

if (condition) instructionselse if (condition) instructions...«else instructions»switch (variable){   case case1:   instructions   «break_or_jump_statement»  ...  «default:   instructions   break_or_jump_statement»}

กรณีที่ไม่ว่างเปล่าทั้งหมดต้องลงท้ายด้วย คำสั่ง " breakหรือ" goto case(กล่าวคือ ไม่อนุญาตให้ข้ามไปยังกรณีถัดไป) defaultกรณีดังกล่าวไม่จำเป็นต้องอยู่เป็นกรณีสุดท้าย

condition?valueIfTrue:valueIfFalse
คริสตัลif condition   statementselse  statementsendif condition1  statementselsif condition2  statements...else  statementsendcase valuewhen case1instructionswhen case2

instructions...elseinstructionsend

condition ? true_val : false_val
วินโดวส์ พาวเวอร์เชลล์if (condition) instruction«else instructions»if (condition) { instructions }elseif (condition) { instructions }...«else { instructionsswitch (variable) { case1{instructions «break;» } ... «default { instructions }»}
ไปif condition {instructions}«else {instructionsif condition {instructions}else if condition {instructions}...«else {instructionsหรือswitch {   case condition: instructions  ...  «default: instructions»}switch variable {   case case1: instructions  ...  «default: instructions»}
สวิฟต์if condition {instructions}«else {instructionsif condition {instructions}else if condition {instructions}...«else {instructionsswitch variable {   case case1: instructions  ...  «default: instructions»}
เพิร์ลif (condition) {instructions}«else {instructionsหรือunless (notcondition) {instructions}«else {instructionsif (condition) {instructions}elsif (condition) {instructions}...«else {instructionsหรือunless (notcondition) {instructions}elsif (condition) {instructions}...«else {instructionsuse feature "switch";...given (variable) {   when (case1) { instructions }  ...  «default { instructions }»}condition?valueIfTrue:valueIfFalse
แร็กเก็ต(when testexpression expressions)หรือ(unless condition expressions)(cond [testexpression expressions] [testexpression expressions]... [else expressions])(case expression [(case1) expressions] [(case2) expressions]... [else expressions])(if testexpression expressioniftrue expressioniffalse)
ราคุif condition {instructions}«else {instructionsหรือunless notcondition {instructions}if condition {instructions}elsif condition {instructions}...«else {instructions}given variable {   when case1 { instructions }  ...  «default { instructions }»}condition??valueIfTrue !! valueIfFalse
ทับทิมif condition  instructions«else  instructions»if condition  instructionselsif condition  instructions...«else  instructions»endcase variable  when case1   instructions  ...  «else   instructions»endcondition?valueIfTrue:valueIfFalse
สกาล่าif (condition) {instructions}«else {instructionsif (condition) {instructions}else if (condition) {instructions}...«else {instructionsexpression match {   case pattern1 => expression  case pattern2 => expression  ...  «case _ => expression»}[ข]if (condition) valueIfTrue else valueIfFalse
การสนทนาเล็กๆ น้อยๆcondition ifTrue:  trueBlock«ifFalse:  falseBlock»endcondition ifTrue: trueBlock ifFalse: falseBlock
ลิสปาร์กทั่วไป(when condition  instructions)หรือหรือ(unless condition  instructions)(if condition  (progn instructions)  «(progn instructions)»)(cond (condition1 instructions)  (condition2 instructions)  ...  «(t instructions)»)(case expression  (case1 instructions)  (case2 instructions)  ...  «(otherwise instructions)»)(if test then else)หรือ(cond (test1 value1) (test2 value2) ...))
โครงการ(when condition instructions)หรือ(if condition (begin instructions) «(begin instructions)»)(cond (condition1 instructions) (condition2 instructions) ... «(else instructions)»)(case (variable) ((case1) instructions) ((case2) instructions) ... «(else instructions)»)(if condition valueIfTrue valueIfFalse)
ไอเอสลิสป์(if condition  (progn instructions)  «(progn instructions)»)(cond (condition1 instructions)  (condition2 instructions)  ...  «(t instructions)»)(case expression  (case1 instructions)  (case2 instructions)  ...  «(t instructions)»)(if condition valueIfTrue valueIfFalse)
ปาสคาลif condition then begin  instructionsend«else begin  instructionsend»'[ค]if condition then begin  instructionsendelse if condition then begin  instructionsend...«else begin  instructionsend»[ค]case variable of  case1: instructions  ...  «else: instructions»end[ค]
วิชวลเบสIf condition Then  instructions«Else  instructions»End Ifบรรทัดเดียว เมื่อใดจึงinstructionsใช้:instruction1 : instruction2 : ...If condition Then instructions «Else instructions»If condition Then  instructionsElseIf condition Then  instructions...«Else  instructions»End Ifบรรทัดเดียว: โปรดดูหมายเหตุเกี่ยวกับภาษาที่คล้าย C; Elseส่วนของคำสั่งบรรทัดเดียว สามารถมี คำสั่ง Ifบรรทัดเดียวอื่นอยู่ภายในได้IfSelect« Case» variable  Case case_pattern1   instructions  ...  «Case Else   instructions»End SelectIIf(condition, valueIfTrue, valueIfFalse)
Visual Basic .NETIf(condition, valueIfTrue, valueIfFalse)
โซโจ
ไพธอน[a]if condition :Tab ↹instructions«else:Tab ↹instructions»if condition :Tab ↹instructionselif condition :Tab ↹instructions...«else:Tab ↹instructions»Python 3.10 ขึ้นไป:match variable:Tab ↹case case1:Tab ↹Tab ↹instructionsTab ↹case case2:Tab ↹Tab ↹instructionsPython 2.5 ขึ้นไป:valueIfTrue if condition else valueIfFalse
เอส-ลังif (condition) { instructions } «else { instructionsif (condition) { instructions } else if (condition) { instructions } ... «else { instructionsswitch (variable) { case case1: instructions } { case case2: instructions } ...
ฟอร์ทรานIF (condition) THEN  instructionsELSE  instructionsENDIFIF (condition) THEN  instructionsELSEIF (condition) THEN  instructions...ELSE  instructionsENDIFSELECT CASE(variable)  CASE (case1)   instructions  ...  CASE DEFAULT   instructionsEND SELECT
ไปข้างหน้าcondition IF instructions « ELSE instructions» THENcondition IF instructions ELSE condition IF instructions THEN THENvalue CASE  case OF instructions ENDOF  case OF instructions ENDOF   default instructionsENDCASEcondition IF valueIfTrue ELSE valueIfFalse THEN
โอแคมล์if condition then begin instructions end «else begin instructions end»if condition then begin instructions end else if condition then begin instructions end ... «else begin instructions end»match value with   pattern1 -> expression  | pattern2 -> expression  ...  «| _ -> expression»[ข]if condition then valueIfTrue else valueIfFalse
เอฟ#โหมดไวยากรณ์แบบเบา:

สามารถเขียนได้ทั้งแบบบรรทัดเดียวหรือแบบเว้นวรรคตามที่แสดงด้านล่าง: โหมดไวยากรณ์แบบละเอียด: เหมือนกับ ML มาตรฐาน if condition thenTab ↹instructions«elseTab ↹instructions»

โหมดไวยากรณ์แบบเบา: เขียนได้ทั้งแบบบรรทัดเดียวหรือแบบมีเยื้องตามที่แสดงด้านล่างโหมดไวยากรณ์แบบละเอียด: เหมือนกับ ML มาตรฐาน if condition thenTab ↹instructionselif condition thenTab ↹instructions...«elseTab ↹instructions»
มาตรฐาน MLif condition then «(»instructions «)»else «(» instructions «if condition then «(»instructions «)»else if condition then «(» instructions «...else «(» instructions «case value of  pattern1 => expression  | pattern2 => expression  ...  «| _ => expression»[ข]
ฮัสเคลล์ ( GHC ) if condition then expression else expressionหรือหรือwhen condition (do instructions)unless notcondition (do instructions)result | condition = expression  | condition = expression  | otherwise = expressioncase value of {   pattern1 -> expression;  pattern2 -> expression;  ...  «_ -> expression»}[ข]
เปลือกหอยif condition-command; then  expression«else  expression»fiif condition-command; then  expressionelif condition-command; then  expression«else  expression»ficase "$variable" in  "$condition1" )   command...  "$condition2" )   command...esac
คอฟฟี่สคริปต์if condition then expression «else expression»หรือหรือหรือหรือif condition  expression«else  expression»expression if conditionunless condition  expression«else  expression»expression unless conditionif condition then expression else if condition then expression «else expression»หรือหรือif condition  expressionelse if condition  expression«else  expression»unless condition  expressionelse unless condition  expression«else  expression»switch expression  when condition then expression  else expressionหรือswitch expression  when condition   expression  «else   expression»เงื่อนไขทั้งหมดเป็นนิพจน์
โคบอลIF condition «THEN»  expression«ELSE  expression».[ง]EVALUATE expression «ALSO expression...»  WHEN case-or-condition «ALSO case-or-condition...»   expression  ...  «WHEN OTHER   expression»END-EVALUATE
สนิมif condition {   expression}« else {   expressionif condition {   expression} else if condition {  expression}« else {  expression}»match variable {   pattern1 => expression,  pattern2 => expression,  pattern3 => expression,  «_ => expression»}[เป็น]เงื่อนไขทั้งหมดเป็นนิพจน์
ถ้า มิฉะนั้นถ้า เลือกกรณีนิพจน์เงื่อนไข
  • ^aคำสั่งเดียวสามารถเขียนได้ในบรรทัดเดียวกันหลังเครื่องหมายโคลอน คำสั่งหลายคำสั่งจะถูกจัดกลุ่มไว้ด้วยกันในบล็อกซึ่งขึ้นบรรทัดใหม่ (จำเป็นต้องมีการเว้นวรรค) ไวยากรณ์ของนิพจน์เงื่อนไขไม่เป็นไปตามกฎนี้
  • ^bนี่คือการจับคู่รูปแบบซึ่งคล้ายกับ select case แต่ไม่เหมือนกันเสียทีเดียว โดยปกติแล้วจะใช้ในการแยกส่วนข้อมูลเชิงพีชคณิต
  • ^cในภาษาตระกูลปาสคาล เครื่องหมายเซมิโคลอนไม่ได้เป็นส่วนหนึ่งของประโยค แต่เป็นตัวคั่นระหว่างประโยค ไม่ใช่ตัวจบประโยค
  • สามารถใช้ ^dEND-IFแทนจุดท้ายประโยคได้
  • ใน Rust สามารถละเว้น เครื่องหมายจุลภาค (,) ที่ส่วนท้ายของเงื่อนไขการจับคู่ได้หลังจากเงื่อนไขการจับคู่สุดท้าย หรือหลังจากเงื่อนไขการจับคู่ใดๆ ที่นิพจน์เป็นบล็อก (ลงท้ายด้วยวงเล็บที่อาจว่างเปล่า{})
ลูป whileวนลูป do whileลูป (ควบคุมการนับ)สำหรับแต่ละ
อาดา[ 1 ]while condition loop  statementsend looploop  statements  exit when not conditionend loopfor index in «reverse» [first .. last | discrete_type] loop  statementsend loopfor item of «reverse» iterator loop  statementsend loopหรือ[b](for [all | some] [in | of] [first .. last | discrete_type | iterator] => predicate)
อัลโกล 68«for index» «from first» «by increment» «to last» «while condition» do statements odfor key «to upb list» do «typename val=list[key];» statements od
«while condition»  do statements od«while statements; condition»  do statements od«for index» «from first» «by increment» «to last» do statements od
เอพีแอล:While condition  statements:EndWhile:Repeat  statements:Until condition:For var«s» :In list  statements:EndFor:For var«s» :InEach list  statements:EndFor
ซี ( ซี99 ) instructionsอาจเป็นข้อความเดียวหรือเป็นกลุ่มข้อความในรูปแบบ:{ statements }while (condition) instructionsdo instructions while (condition);for («type» i = first; i <= last; i++) instructionsไม่มีข้อมูล
ออบเจกทีฟซีfor (type item in set) instructions
ซี++ (STL) «std::»for_each(start, end, function)ตั้งแต่C++11 เป็นต้นมา :for (type item : set) instructions
ซี#foreach (type item in set) instructions
ชวาfor (type item : set) instructions
โค้ด JavaScriptfor (var i = first; i <= last; i++) instructionsตั้งแต่EcmaScript 2015: [ 11 ]

for (var item of set) instructions

พีพีforeach (range(first, last) as $i) instructionsหรือfor ($i = first; $i <= last; $i++) instructionsforeach (set as item) instructionsหรือforeach (set as key => item) instructions
วินโดวส์ พาวเวอร์เชลล์for ($i = first; $i -le last; $i++) instructionsforeach (item in set) instructions
ดีforeach (i; first ... last) instructionsforeach («type» item; set) instructions
ไปfor condition { instructions }for i := first; i <= last; i++ { instructions }for key, item := range set { instructions }
สวิฟต์while condition { instructions }2.x: 1.x:repeat { instructions } while conditiondo { instructions } while conditionfor i = first ... last { instructions }หรือหรือfor i = first ..< last+1 { instructions }for var i = first; i <= last; i++ { instructions }for item in set { instructions }
เพิร์ลwhile (condition) { instructions }หรือuntil (notcondition) { instructions }do { instructions } while (condition)หรือdo { instructions } until (notcondition)for«each» «$i» (first .. last) { instructions }หรือfor ($i = first; $i <= last; $i++) { instructions }for«each» «$item» (set) { instructions }
ราคุwhile condition { instructions }หรือuntil notcondition { instructions }repeat { instructions } while conditionหรือrepeat { instructions } until notconditionfor first..last -> $i { instructions }หรือloop ($i = first; $i <=last; $i++) { instructions }for set« -> $item» { instructions }
ทับทิมwhile condition  instructionsendหรือuntil notcondition  instructionsendbegin  instructionsend while conditionหรือbegin  instructionsend until notconditionfor i in first..last  instructionsendหรือหรือfor i in first...last+1  instructionsendfirst.upto(last) { |i| instructions }for item in set  instructionsendหรือset.each { |item| instructions }
เปลือกหอยwhile condition ;do  instructionsdoneหรือuntil notcondition ;do  instructionsdoneไม่มีข้อมูลfor ((i = first; i <= last; ++i)) ; do  instructionsdonefor item in set ;do  instructionsdone
สกาล่าwhile (condition) { instructions }do { instructions } while (condition)for (i <- first to last «by 1») { instructions }หรือfirst to last «by 1» foreach (i => { instructions })for (item <- set) { instructions }หรือset foreach (item => { instructions })
การสนทนาเล็กๆ น้อยๆconditionBlock whileTrue:  loopBlockloopBlock doWhile:  conditionBlockfirst to: last do:  loopBlockcollection do:  loopBlock
ลิสปาร์กทั่วไป(loop  while condition  do  instructions)หรือ(do () (notcondition)  instructions)(loop  do  instructions  while condition)(loop  for i from first to last «by 1»  do  instructions)หรือหรือ(dotimes (i N)  instructions)(do ((i first(1+i)))((>=ilast))  instructions)(loop  for item in list  do  instructions)หรือหรือหรือหรือ(loop  for item across vector  do  instructions)(dolist (item list)  instructions)(mapc function list)(map type function sequence)
โครงการ(do () (notcondition) instructions)หรือ(letloop()(ifcondition (begin instructions (loop))))(letloop()(instructions (if condition (loop))))(do ((i first(+i1)))((>=ilast)) instructions)หรือ(letloop((ifirst1))(if(<ilast) (begin instructions(loop(+i1)))))(for-each(lambda(item) instructions) list)
ไอเอสลิสป์(while condition instructions)(tagbodyloopinstructions (if condition(goloop))(for((ifirst(+i1)))((>=ilast)) instructions)(mapc(lambda(item) instructions) list)
ปาสคาลwhile condition do begin  instructionsendrepeat  instructionsuntil notcondition;for i := first «step 1» to last do begin  instructionsend;[ก]for item in set do instructions
วิชวลเบสDo While condition  instructionsLoopหรือหรือ(Visual Basic .NET ใช้แทน) Do Until notcondition  instructionsLoopWhile condition  instructionsWendEnd WhileDo  instructionsLoop While conditionหรือDo  instructionsLoop Until notconditioniต้องแจ้งให้ทราบล่วงหน้า

For i = first To last «Step 1»  instructionsNext i

For Each item In set  instructionsNext item
Visual Basic .NETFor i« As type» = first To last« Step 1»  instructionsNext« i»[ก]For Each item« As type» In set  instructionsNext« item»
โซโจWhile condition  instructionsWendDo Until notcondition  instructionsLoopหรือDo  instructionsLoop Until notcondition
ไพธอนwhile condition :Tab ↹instructions«else:Tab ↹instructions»ไม่มีข้อมูลPython 3.x: Python 2.x:foriinrange(first, last+1):Tab ↹instructions«else:Tab ↹instructions»foriinxrange(first, last+1):Tab ↹instructions«else:Tab ↹instructions»for item in set:Tab ↹instructions«else:Tab ↹instructions»
เอส-ลังwhile (condition) { instructions } «then optional-block»do { instructions } while (condition) «then optional-block»for (i = first; i <= last; i++) { instructions } «then optional-block»foreach item(set) «using (what)» { instructions } «then optional-block»
ฟอร์ทรานDO WHILE (condition)  instructionsENDDODO  instructions  IF (condition) EXITENDDODO I = first,last  instructionsENDDOไม่มีข้อมูล
ไปข้างหน้าBEGIN «instructions» condition WHILE instructions REPEATBEGIN instructions condition UNTILlimit start DO instructions LOOPไม่มีข้อมูล
โอแคมล์while condition do instructions doneไม่มีข้อมูลfor i = first to last do instructions doneArray.iter (fun item -> instructions) arrayหรือList.iter (fun item -> instructions) list
เอฟ#while condition doTab ↹instructionsไม่มีข้อมูลfor i = first to last doTab ↹instructionsfor item in set doTab ↹instructionsหรือSeq.iter (fun item -> instructions) set
มาตรฐาน MLwhile condition do ( instructions )ไม่มีข้อมูลArray.app (fn item => instructions) arrayหรือapp (fn item => instructions) list
ฮัสเคลล์ ( GHC ) ไม่มีข้อมูลControl.Monad.forM_ [first..last] (\i -> do instructions)Control.Monad.forM_list (\item -> do instructions)
หอไอเฟลfrom  setupuntil  conditionloop  instructionsend
คอฟฟี่สคริปต์while condition  expressionหรือหรือหรือหรือหรือexpression while conditionwhile condition then expressionuntil condition  expressionexpression until conditionuntil expression then conditionไม่มีข้อมูลfor i in [first..last]  expressionหรือหรือfor i in [first..last] then expressionexpression for i in [first..last]for item in set  expressionหรือหรือfor item in set then expressionexpression for item in set
โคบอลPERFORM procedure-1 «THROUGH procedure-2» ««WITH»TESTBEFORE»UNTILcondition[ค]หรือPERFORM ««WITH»TESTBEFORE»UNTILcondition  expressionEND-PERFORMPERFORM procedure-1 «THROUGH procedure-2» «WITH»TESTAFTERUNTILcondition[ค]หรือPERFORM «WITH»TESTAFTERUNTILcondition  expressionEND-PERFORMPERFORM procedure-1 «THROUGH procedure-2» VARYING i FROM first BY increment UNTIL i > last[d]หรือ [d]PERFORM VARYING i FROM first BY increment UNTIL i > last  expressionEND-PERFORMไม่มีข้อมูล
สนิมwhile condition {   expression}loop {   expression   if condition {     break;  }}for i in first..last+1 {   expression}หรือfor i in first..=last {   expression}for item in set {   expression}[e]หรือ [e]set.into_iter().for_each(|item| expression);
  • ^a "stepn" ใช้สำหรับเปลี่ยนช่วงเวลาการวนซ้ำ หากstepละเว้น " " ช่วงเวลาการวนซ้ำจะเป็น 1
  • ^bนี่เป็นการนำตัวบ่งปริมาณสากล("สำหรับทั้งหมด" หรือ) และตัวบ่งปริมาณเชิงการมีอยู่ ("มีอยู่" หรือ)
  • THRUสามารถใช้ ^cTHROUGH แทน .
  • สามารถใช้ ^d แทน .«IS»GREATER «THAN»>
  • ^eประเภทของนิพจน์เซตต้องใช้งาน traitstd::iter::IntoIterator.
โยน แฮนด์เลอร์ การยืนยัน
อาดา[ 1 ]raise exception_name «with string_expression»begin  statementsexception  when exception_list1 => statements;  when exception_list2 => statements;...  «when others => statements;»end[ข]pragmaAssert («Check =>» boolean_expression ««Message =>» string_expression»)[function | procedure | entry] with  Pre => boolean_expression  Post => boolean_expressionany_type with Type_Invariant => boolean_expression
เอพีแอล«string_expression» ⎕SIGNAL number_expression:Trap number«s»_expression  statements«:Case number«s»_expression  statements»...«:Else number«s»_expression  statements»:EndTrap«string_expression»⎕SIGNAL98/⍨~condition
ซี ( ซี99 ) longjmp(state, exception);switch (setjmp(state)) { case 0: instructions break; case exception: instructions ... }assert(condition);
ซี++throw exception;try { instructions } catch «(exception)» { instructions } ...
ซี#try { instructions } catch «(exception« name»)» { instructions } ... «finally { instructionsSystem.Diagnostics.Debug.Assert(condition);หรือSystem.Diagnostics.Trace.Assert(condition);
ชวาtry { instructions } catch (exception) { instructions } ... «finally { instructionsassert condition «: description»;
โค้ด JavaScripttry { instructions } catch (exception) { instructions} «finally { instructions?
ดีtry { instructions } catch (exception) { instructions } ... «finally { instructionsassert(condition);
พีพีtry { instructions } catch (exception) { instructions } ... «finally { instructionsassert(condition);
เอส-ลังtry { instructions } catch «exception» { instructions } ... «finally { instructions?
วินโดวส์ พาวเวอร์เชลล์trap «[exception]» { instructions } ... instructionsหรือtry { instructions } catch «[exception]» { instructions } ... «finally { instructions[Debug]::Assert(condition)
ออบเจกทีฟซี@throw exception;@try { instructions } @catch (exception) { instructions } ... «@finally { instructionsNSAssert(condition, description);
คริสตัลraise exception.newbegin

instructionsrescue exceptioninstructions...elseinstructionsensureinstructionsend

สวิฟต์throw exception(2.x) do { try expression ... instructions } catch exception { instructions } ...(2.x) assert(condition«, description»)
เพิร์ลdie exception;eval { instructions};if($@){instructions }?
ราคุtry { instructions CATCH { when exception { instructions } ...}}?
ทับทิมraise exceptionbegin  instructionsrescue exception  instructions...«else  instructions»«ensure  instructions»end
การสนทนาเล็กๆ น้อยๆexception raiseinstructionBlock on: exception do: handlerBlockassert: conditionBlock
ลิสปาร์กทั่วไป(error "exception")หรือหรือ(error  type  arguments)(error (make-condition  type  arguments))(handler-case  (progn instructions)  (exception instructions)  ...)หรือ[ก](handler-bind  (condition   (lambda   instructions   «invoke-restart restart args»))...)(assert condition)หรือหรือ(assert condition  «(place)  «error»»)(check-type var type)
โครงการ ( R 6 RS ) (raise exception)(guard (con (condition instructions) ...) instructions)?
ไอเอสลิสป์(error "error-string" objects)หรือ(signal-condition condition continuable)(with-handler  handler form*)?
ปาสคาลraise Exception.Create()try Except on E: exception do begin instructions end; end;?
วิชวลเบสErr.Raise ERRORNUMBERWithNewTry:OnErrorResumeNext  OneInstruction.Catch:OnErrorGoTo0:SelectCase.Number  Case SOME_ERRORNUMBER   instructionsEndSelect:EndWith
'*** คลาส Try *** Private mstrDescription As String Private mlngNumber As LongPublic Sub Catch () mstrDescription = Err . Description mlngNumber = Err . Number End Subคุณสมบัติสาธารณะรับหมายเลข() เป็นหมายเลขยาว= mlngNumber สิ้นสุดคุณสมบัติคุณสมบัติสาธารณะรับคำอธิบาย() เป็นสตริงคำอธิบาย= mstrDescription สิ้นสุดคุณสมบัติ
[ 12 ]
Debug.Assert condition
Visual Basic .NETThrow exceptionหรือError errorcodeTry  instructionsCatch« name As exception»« When condition»  instructions...«Finally  instructions»End TrySystem.Diagnostics.Debug.Assert(condition)หรือSystem.Diagnostics.Trace.Assert(condition)
โซโจRaise exceptionTry  instructionsCatch «exception»  instructions...«Finally  instructions»End Tryไม่มีข้อมูล
ไพธอนraise exceptiontry:Tab ↹instructionsexcept «exception»:Tab ↹instructions...«else:Tab ↹instructions»«finally:Tab ↹instructions»assert condition
ฟอร์ทรานไม่มีข้อมูล
ไปข้างหน้าcode THROWxt CATCH ( code or 0 )ไม่มีข้อมูล
โอแคมล์raise exceptiontry expression with pattern -> expression ...assert condition
เอฟ#try expression with pattern -> expression ...หรือtry expression finally expression
มาตรฐาน MLraise exception «arg»expression handle pattern => expression ...
ฮัสเคลล์ ( GHC ) throw exceptionหรือthrowError expressioncatch tryExpression catchExpressionหรือcatchError tryExpression catchExpressionassert condition expression
โคบอลRAISE «EXCEPTION»exceptionUSE «AFTER»EXCEPTIONOBJECTclass-name.หรือหรือหรือUSE «AFTER»EOclass-name.USE «AFTER»EXCEPTIONCONDITIONexception-name «FILE file-name».USE «AFTER»ECexception-name «FILE file-name».ไม่มีข้อมูล
สนิมหมายเลข[ 13 ]assert!(condition)
  • ภาษา Common Lisp อนุญาตให้with-simple-restartกำหนดการเริ่มต้นใหม่เพื่อใช้กับเงื่อนไขที่ไม่ได้รับการจัดการอาจทำให้การใช้งานแสดงเมนูการเริ่มต้นใหม่แก่ผู้ใช้ก่อนที่จะคลายสแต็กrestart-caserestart-bindinvoke-restart
  • ^bข้อผิดพลาดที่ไม่ได้รับการจัดการจะถูกส่งต่อไปยังการดำเนินการแบบไดนามิกที่อยู่ภายในสุด ข้อผิดพลาดจะไม่ถูกส่งต่อระหว่างงานต่างๆ (เว้นแต่ว่างานเหล่านั้นจะถูกซิงโครไนซ์ในการนัดพบกันอยู่แล้ว)

คำสั่งควบคุมการไหลอื่นๆ

บล็อกทางออก (เบรก) ดำเนินการต่อ ฉลากสาขา ( goto ) ค่าส่งคืนจากตัวสร้าง
อาดา[ 1 ]exit «loop_name» «when condition»ไม่มีข้อมูลlabel:goto labelไม่มีข้อมูล
อัลโกล 68value exit;... do statements; skip exit; label: statements odlabel:... go to label; ...goto label; ...label; ...yield(value)

( การเรียกกลับ ) [ 14 ]

เอพีแอล:Leave:Continuelabel:labelหรือ:GoTo labelไม่มีข้อมูล
ซี ( ซี99 ) break;continue;label:goto label;ไม่มีข้อมูล
ออบเจกทีฟซี
ซี++ (STL)
ดี
ซี#yield return value;
ชวาbreak «label»;continue «label»;ไม่มีข้อมูล
โค้ด JavaScriptyield value«;»
พีพีbreak «levels»;continue «levels»;goto label;yield «key =>» value;
เพิร์ลlast «label»;next «label»;
ราคุ
ไปbreak «label»continue «label»goto label
สวิฟต์break «label»continue «label»ไม่มีข้อมูล
เปลือกหอยbreak «levels»continue «levels»ไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
ลิสปาร์กทั่วไป(return)หรือหรือ(return-from block)(loop-finish)(tagbody tag  ...  tag...)(go tag)
คริสตัลbreaknextค่าการเรียงลำดับข้อมูล="" สไตล์="พื้นหลัง: var(--background-color-interactive, #ececec); สี: var(--color-base, inherit); จัดแนวตั้ง: ตรงกลาง; จัดแนวข้อความ: ตรงกลาง; " คลาส="table-na" | ไม่มีข้อมูลyield value
โครงการ
ไอเอสลิสป์(return-from block)(tagbody tag  ...  tag...)(go tag)
ปาสคาล (ISO) ไม่มีข้อมูลlabel:[ก]goto label;ไม่มีข้อมูล
ปาสคาล ( FPC ) break;continue;
วิชวลเบสExit blockหรืออีกทางเลือกหนึ่ง สำหรับวิธีการต่างๆReturnไม่มีข้อมูลlabel:GoTo label
โซโจContinue block
Visual Basic .NETYield value
ไพธอนbreakcontinueไม่มีข้อมูลyield value
RPG IVLEAVE;ITER;
เอส-ลังbreak;continue;
ฟอร์ทรานEXITCYCLElabel[ข]GOTO labelไม่มีข้อมูล
ทับทิมbreaknext
วินโดวส์ พาวเวอร์เชลล์break «label»continue
โอแคมล์ไม่มีข้อมูล
เอฟ#
มาตรฐาน ML
ฮัสเคลล์ ( GHC )
โคบอลEXIT PERFORMหรือEXIT PARAGRAPHหรือEXIT SECTIONหรือEXIT.EXIT PERFORM CYCLElabel «SECTION».GO TO labelไม่มีข้อมูล
  • ภาษาปาสคาลมีบล็อกการประกาศ ดูที่ฟังก์ชัน
  • ^b label ต้องเป็นตัวเลขระหว่าง 1 ถึง 99999

ดูการเขียนโปรแกรมแบบสะท้อนกลับ (reflective programming)สำหรับการเรียกและการประกาศฟังก์ชันโดยใช้สตริง

การเรียกใช้ฟังก์ชัน ฟังก์ชันพื้นฐาน/ว่างเปล่า ฟังก์ชันส่งคืนค่า ฟังก์ชันหลักที่จำเป็น
อาดา[ 1 ]foo «(parameters)»procedure foo «(parameters)» is begin statements end foofunction foo «(parameters)» return type is begin statements end fooไม่มีข้อมูล
อัลโกล 68foo «(parameters)»;proc foo = «(parameters)»void: ( instructions );proc foo = «(parameters)» rettype: ( instructions ...; retvalue );ไม่มีข้อมูล
เอพีแอล«parameters» foo parametersfoo←{ statements }foo←{ statements }ไม่มีข้อมูล
ซี ( ซี99 ) foo(«parameters»)voidfoo(«parameters») { instructions }typefoo(«parameters») { instructions ... return value; }«global declarations»intmain(«intargc,char*argv[]») {   instructions}
ออบเจกทีฟซี
ซี++ (STL)
ชวาpublicstaticvoidmain(String[]args) { instructions }หรือpublicstaticvoidmain(String... args) { instructions }
ดีintmain(«char[][]args») { instructions}หรือหรือหรือintmain(«string[]args») { instructions}voidmain(«char[][]args») { instructions}voidmain(«string[]args») { instructions}
ซี#เช่นเดียวกับข้างต้น หรือหากต้องการข้อความเพียงข้อเดียว:

void foo(«parameters») => statement;

เช่นเดียวกับข้างต้น หรืออีกทางเลือกหนึ่ง หากง่ายพอที่จะเป็นการแสดงออก:

void foo(«parameters») => expression;

staticvoidMain(«string[]args»)method_bodyอาจส่งคืนค่าอื่นแทนint( เริ่มตั้งแต่ C# 7.1:) อาจส่งคืนค่าTaskหรือและถ้าเป็นเช่นนั้น อาจเป็น Task<int>async
โค้ด JavaScriptfunction foo(«parameters») { instructions }หรือหรือvarfoo=function(«parameters») { instructions }varfoo=newFunction("«parameter»", ..., "«last parameter»" "instructions");function foo(«parameters») { instructions ... return value; }ไม่มีข้อมูล
ไปfunc foo(«parameters») { instructions }funcfoo(«parameters») type { instructions ... return value }funcmain(){|goinstructions }
สวิฟต์funcfoo(«parameters») { instructions }funcfoo(«parameters») -> type { instructions ... return value }ไม่มีข้อมูล
คริสตัลfoo(parameters)

หรือ foo parameters[f]

def foo(parameters)

instructionsend

def foo(parameters) : type

instructionsreturn_valueend[e]

ไม่มีข้อมูล
ลิสปาร์กทั่วไป(foo «parameters»)(defun foo («parameters»)  instructions)หรือ(setf(symbol-function'symbol)  function)(defun foo («parameters»)  ...  value)ไม่มีข้อมูล
โครงการ(define (foo parameters) instructions)หรือ(define foo (lambda (parameters) instructions))(define (foo parameters) instructions... return_value)หรือ(define foo (lambda (parameters) instructions... return_value))
ไอเอสลิสป์(defun foo («parameters»)  instructions)(defun foo («parameters»)  ...  value)
ปาสคาลfoo«(parametersprocedure foo«(parameters)»; «forward;»[a]«label  label declarations»«const  constant declarations»«type  type declarations»«var  variable declarations»«local function declarations»begin  instructionsend;function foo«(parameters)»: type; «forward;»[a]«label  label declarations»«const  constant declarations»«type  type declarations»«var  variable declarations»«local function declarations»begin  instructions;  foo := valueend;program name;«label  label declarations»«const  constant declarations»«type  type declarations»«var  variable declarations»«function declarations»begin  instructionsend.
วิชวลเบสFoo(«parameters»)Sub Foo«(parameters)»  instructionsEnd SubFunction Foo«(parameters)»« As type»  instructions  Foo = valueEnd FunctionSub Main()  instructionsEnd Sub
Visual Basic .NETเช่นเดียวกับข้างต้น หรืออีกทางเลือกหนึ่ง:

Function Foo«(parameters)»« As type»  instructions  Return valueEnd FunctionAsไม่จำเป็นต้องใช้ข้อความนี้ หาก Option Strictปิดอยู่ สามารถใช้ตัวอักขระระบุประเภทแทนAsข้อความ นี้ได้ หากการควบคุมออกจากฟังก์ชันโดยไม่ได้ระบุค่าส่งคืนอย่างชัดเจน ฟังก์ชันจะส่งคืนค่าเริ่มต้นสำหรับประเภทการส่งคืน

SubMain(««ByVal»args()AsString»)  instructionsEnd SubหรือFunctionMain(««ByVal»args()AsString»)AsInteger  instructionsEnd Function
โซโจ
ไพธอนfoo(«parameters»)def foo(«parameters»):Tab ↹instructionsdef foo(«parameters»):Tab ↹instructionsTab ↹return valueไม่มีข้อมูล
เอส-ลังfoo(«parameters» «;qualifiers»)define foo («parameters») { instructions }define foo («parameters») { instructions ... return value; }public define slsh_main () { instructions }
ฟอร์ทรานfoo («arguments»)CALL sub_foo («arguments»)[ค]SUBROUTINE sub_foo («arguments»)  instructionsEND SUBROUTINE[ค]type FUNCTION foo («arguments»)  instructions  ...  foo = valueEND FUNCTION[ค]PROGRAM main  instructionsEND PROGRAM
ไปข้างหน้า«parameters» FOO:FOO«stackeffectcomment: ( before -- ) »  instructions;:FOO«stackeffectcomment: ( before -- after ) »  instructions;ไม่มีข้อมูล
พีพีfoo(«parameters»)function foo(«parameters») { instructions }function foo(«parameters») { instructions ... return value; }ไม่มีข้อมูล
เพิร์ลfoo(«parameters»)หรือ&foo«(parameterssubfoo{«my(parameters) = @_;» instructions }subfoo{«my(parameters) = @_;» instructions... «return» value; }
ราคุfoo(«parameters»)หรือ&foo«(parameters«multi »subfoo(parameters) { instructions }«our «type» »«multi »subfoo(parameters) { instructions ... «return» value; }
ทับทิมfoo«(parametersdef foo«(parameters)»  instructionsenddef foo«(parameters)»  instructions  «return» valueend
สนิมfoo(«parameters»)fn foo(«parameters») { instructions }fn foo(«parameters») -> type { instructions }fn main() { instructions }
สกาล่าfoo«(parametersdef foo«(parameters)»«: Unit =» { instructions }def foo«(parameters)»«: type» = { instructions ... «return» value }defmain(args:Array[String]) { instructions }
วินโดวส์ พาวเวอร์เชลล์foo «parameters»function foo { instructions };หรือfunction foo { «param(parametersinstructions }function foo «(parameters)» { instructions ... return value };หรือfunction foo { «param(parametersinstructions ... return value }ไม่มีข้อมูล
เปลือกหอยfoo «parameters»function foo {  instructions}หรือfoo () {  instructions}function foo {  instructions  return «exit_code»}หรือfoo () {   instructions  return «exit_code»}
  • พารามิเตอร์
    • $n( 1 ดอลลาร์ , 2 ดอลลาร์ , 3 ดอลลาร์ , ... )
    • $@(พารามิเตอร์ทั้งหมด)
    • $#(จำนวนพารามิเตอร์)
    • $0(ชื่อฟังก์ชันนี้)
โอแคมล์foo parameterslet «rec» foo parameters = instructionslet «rec» foo parameters = instructions... return_value
เอฟ#[<EntryPoint>]letmainargs = instructions
มาตรฐาน MLfun foo parameters = ( instructions )fun foo parameters = ( instructions... return_value )
ฮัสเคลล์foo parameters = doTab ↹instructionsfoo parameters = return_valueหรือfoo parameters = doTab ↹instructionsTab ↹return value«main::IO()»main = do instructions
หอไอเฟลfoo («parameters»)foo («parameters»)  require   preconditions  do   instructions  ensure   postconditions  endfoo («parameters»): type  require   preconditions  do   instructions   Result := value  ensure   postconditions  end[ข]
คอฟฟี่สคริปต์foo()foo=->foo=->valueไม่มีข้อมูล
foo parametersfoo=() ->foo = ( parameters ) -> value
โคบอลCALL "foo" «USING parameters»  «exception-handling»«END-CALL»[ง]«IDENTIFICATION DIVISION.»PROGRAM-ID. foo.«other divisions...»PROCEDURE DIVISION «USING parameters».  instructions.«IDENTIFICATION DIVISION.»PROGRAM-ID/FUNCTION-ID. fooother divisions...»DATA DIVISION.«other sections...»LINKAGE SECTION.«parameter definitions...»variable-to-return definition«other sections...»PROCEDURE DIVISION «USING parameters» RETURNING variable-to-return.  instructions.ไม่มีข้อมูล
«FUNCTION» foo«(«parameters»)»ไม่มีข้อมูล
  • ภาษาปาสคาลต้องการ "forward;" สำหรับประกาศล่วงหน้า
  • ^b Eiffel อนุญาตให้ระบุคลาสหลักและฟีเจอร์ของแอปพลิเคชันได้
  • ใน ภาษา Fortran พารามิเตอร์ของฟังก์ชัน/ซับรูทีนเรียกว่า อาร์กิวเมนต์ (เนื่องจากPARAMETERเป็นคำสำคัญของภาษา) และCALLคำสำคัญนี้จำเป็นสำหรับซับรูทีน
  • ^dแทนที่จะใช้"foo"สามารถใช้ตัวแปรสตริงที่มีค่าเดียวกันแทนได้
  • ใน Crystal คำหลักนี้ไม่returnจำเป็น แต่คำสั่งสุดท้ายในลำดับการควบคุมของฟังก์ชันจะถูกพิจารณาว่าเป็นค่าส่งคืน
  • ^fการเรียกใช้ฟังก์ชันใน Crystal จำเป็นต้องมีวงเล็บครอบพารามิเตอร์เฉพาะในกรณีที่มีความกำกวมทางไวยากรณ์ (ตัวอย่างเช่น เมื่อฟังก์ชันที่รับพารามิเตอร์หลายตัวถูกส่งเป็นพารามิเตอร์ไปยังฟังก์ชันอื่น) หรือเมื่อประกาศฟังก์ชัน

โดยที่stringเป็นตัวเลขทศนิยมที่มีเครื่องหมาย:

แปลงสตริงเป็นจำนวนเต็ม แปลงสตริงเป็นจำนวนเต็มยาว แปลงสตริงเป็นเลขทศนิยม แปลงจำนวนเต็มเป็นสตริง แปลงค่าทศนิยมเป็นสตริง
อาดา[ 1 ]Integer'Value (string_expression)Long_Integer'Value (string_expression)Float'Value (string_expression)Integer'Image (integer_expression)Float'Image (float_expression)
ALGOL 68พร้อมรูปแบบทั่วไปและรูปแบบเฉพาะ โดยได้แจ้งและตกลงร่วมกับบุคคลดังต่อไปนี้:string buf := "12345678.9012e34 "; file proxy; associate(proxy, buf);
get(proxy, ivar);get(proxy, livar);get(proxy, rvar);put(proxy, ival);put(proxy, rval);
getf(proxy, ($g$, ivar));หรือgetf(proxy, ($dddd$, ivar));getf(proxy, ($g$, livar));หรือgetf(proxy, ($8d$, livar));getf(proxy, ($g$, rvar));หรือgetf(proxy, ($8d.4dE2d$, rvar));putf(proxy, ($g$, ival));หรือputf(proxy, ($4d$, ival));putf(proxy, ($g(width, places, exp)$, rval));หรือputf(proxy, ($8d.4dE2d$, rval));
เอพีแอลstring_expressionstring_expressionstring_expressioninteger_expressionfloat_expression
ซี ( ซี99 ) integer = atoi(string);long = atol(string);float = atof(string);sprintf(string, "%i", integer);sprintf(string, "%f", float);
ออบเจกทีฟซีinteger = [string intValue];long = [string longLongValue];float = [string doubleValue];string = [NSStringstringWithFormat:@"%i",integer];string = [NSStringstringWithFormat:@"%f",float];
ซี++ (STL) «std::»istringstream(string) >> number;«std::»ostringstream o; o << number; string = o.str();
ซี++11integer = «std::»stoi(string);long = «std::»stol(string);float = «std::»stof(string); double = «std::»stod(string);string = «std::»to_string(number);
ซี#integer = int.Parse(string);long = long.Parse(string);float = float.Parse(string);double = double.Parse(string);string = number.ToString();
คริสตัลint32 = string.to_i32int64 = string.to_i64float32 = string.to_f32

float64 = string.to_f64

string = number.to_sstring = float.to_s
ดีinteger = std.conv.to!int(string)long = std.conv.to!long(string)float = std.conv.to!float(string)double = std.conv.to!double(string)string = std.conv.to!string(number)
ชวาinteger = Integer.parseInt(string);long = Long.parseLong(string);float = Float.parseFloat(string);double = Double.parseDouble(string);string = Integer.toString(integer);string = String.valueOf(integer);string = Float.toString(float);string = Double.toString(double);
JavaScript [a]integer = parseInt(string);float = parseFloat(string);float = new Number (string);float = Number (string);float = +string;string = number.toString ();string = String (number);string = number+"";string = `${number}`
ไปinteger, error = strconv.Atoi(string)integer, error = strconv.ParseInt(string, 10, 0)long, error = strconv.ParseInt(string, 10, 64)float, error = strconv.ParseFloat(string, 64)string = strconv.Itoa(integer)string = strconv.FormatInt(integer, 10)string = fmt.Sprint(integer)string = strconv.FormatFloat(float)string = fmt.Sprint(float)
สนิม[d]string.parse::<i32>()i32::from_str(string)string.parse::<i64>()i64::from_str(string)string.parse::<f64>()f64::from_str(string)integer.to_string()float.to_string()
ลิสปาร์กทั่วไป(setf integer (parse-integer string))(setf float (read-from-string string))(setf string (princ-to-string number))
โครงการ(define number (string->number string))(define string (number->string number))
ไอเอสลิสป์(setf integer (convert string <integer>))(setf float (convert string <float>))(setf string (convert number <string>))
ปาสคาล integer := StrToInt(string);float := StrToFloat(string);string := IntToStr(integer);string := FloatToStr(float);
วิชวลเบสinteger = CInt(string)long = CLng(string)float = CSng(string)double = CDbl(string)string = CStr(number)
Visual Basic .NET (สามารถใช้ได้ทั้งไวยากรณ์ VB ด้านบนและวิธีการ .NET ที่แสดงทางด้านขวา) integer = Integer.Parse(string)long = Long.Parse(string)float = Single.Parse(string)double = Double.Parse(string)string = number.ToString()
โซโจinteger = Val(string)long = Val(string)double = Val(string)double = CDbl(string)string = CStr(number)หรือstring = Str(number)
ไพธอนinteger = int(string)long = long(string)float = float(string)string = str(number)
เอส-ลังinteger = atoi(string);long = atol(string);float = atof(string);string = string(number);
ฟอร์ทรานREAD(string,format) numberWRITE(string,format) number
พีพีinteger = intval(string);หรือinteger = (int)string;float = floatval(string);float = (float)string;string = "$number";หรือหรือstring = strval(number);string = (string)number;
เพิร์ล[b]number = 0 + string;string = "number";
ราคุnumber = +string;string = ~number;
ทับทิมinteger = string.to_iหรือinteger = Integer(string)float = string.to_ffloat = Float(string)string = number.to_s
สกาล่าinteger = string.toIntlong = string.toLongfloat = string.toFloatdouble = string.toDoublestring = number.toString
การสนทนาเล็กๆ น้อยๆinteger := Integer readFrom: stringfloat := Float readFrom: stringstring := number asString
วินโดวส์ พาวเวอร์เชลล์integer = [int]stringlong = [long]stringfloat = [float]stringstring = [string]number;หรือหรือstring = "number";string = (number).ToString()
โอแคมล์let integer = int_of_string stringlet float = float_of_string stringlet string = string_of_int integerlet string = string_of_float float
เอฟ#let integer = int stringlet integer = int64 stringlet float = float stringlet string = string number
มาตรฐาน MLval integer = Int.fromString stringval float = Real.fromString stringval string = Int.toString integerval string = Real.toString float
ฮัสเคลล์ ( GHC ) number = read stringstring = show number
โคบอลMOVE «FUNCTION»NUMVAL(string)[c] TO numberMOVE number TO numeric-edited
  • JavaScriptใช้เฉพาะตัวเลขทศนิยมเท่านั้น ดังนั้นจึงมีรายละเอียดทางเทคนิคบางอย่าง [ 7 ]
  • ^bภาษา Perl ไม่มีการแบ่งประเภทข้อมูล สตริงและตัวเลขสามารถใช้แทนกันได้
  • ^cNUMVAL-CหรือNUMVAL-Fอาจใช้แทนNUMVAL.
  • ^str::parseสามารถใช้แปลงประเภทใดก็ได้ที่มีการใช้งานstd::str::FromStrtrait ทั้งสองแบบstr::parseจะFromStr::from_strส่งคืนค่าResultที่มีประเภทที่ระบุหากไม่มีข้อผิดพลาดสามารถละเว้นturbofish()::<_>str::parse
อ่านจาก เขียนถึง
stdinstdoutstderr
อาดา[ 1 ]Get (x)Put (x)Put (Standard_Error, x)
อัลโกล 68readf(($format$, x));หรือgetf(stand in, ($format$, x));printf(($format$, x));หรือputf(stand out, ($format$, x));putf(stand error, ($format$, x));[ก]
เอพีแอลx←⎕←x⍞←x
ซี ( ซี99 ) scanf(format, &x);หรือ[b]fscanf(stdin, format, &x);printf(format, x);หรือ[ค]fprintf(stdout, format, x);fprintf(stderr, format, x);[ง]
ออบเจกทีฟซีdata=[[NSFileHandlefileHandleWithStandardInput]readDataToEndOfFile];[[NSFileHandlefileHandleWithStandardOutput]writeData:data];[[NSFileHandlefileHandleWithStandardError]writeData:data];
ซี++«std::»cin >> x;หรือ«std::»getline(«std::»cin, str);«std::»cout << x;«std::»cerr << x;หรือ«std::»clog << x;
ซี#x = Console.Read();หรือx = Console.ReadLine();Console.Write(«format, »x);หรือConsole.WriteLine(«format, »x);Console.Error.Write(«format, »x);หรือConsole.Error.WriteLine(«format, »x);
คริสตัลx = getsputs x

หรือ หรือ หรือ puts(x)printf $format$, xprintf($format$, x)

STDERR.puts x

หรือ STDERR.puts(x) หรือ หรือ STDERR.printf $format$, x

STDERR.printf($format$, x)

ดีx = std.stdio.readln()std.stdio.write(x)หรือหรือหรือstd.stdio.writeln(x)std.stdio.writef(format, x)std.stdio.writefln(format, x)stderr.write(x)หรือหรือหรือstderr.writeln(x)std.stdio.writef(stderr, format, x)std.stdio.writefln(stderr, format, x)
ชวาx=System.in.read();หรือหรือx=newScanner(System.in).nextInt();x=newScanner(System.in).nextLine();System.out.print(x);หรือหรือSystem.out.printf(format, x);System.out.println(x);System.err.print(x);หรือหรือSystem.err.printf(format, x);System.err.println(x);
ไปfmt.Scan(&x)หรือหรือfmt.Scanf(format, &x)x=bufio.NewReader(os.Stdin).ReadString('\n')fmt.Println(x)หรือfmt.Printf(format, x)fmt.Fprintln(os.Stderr, x)หรือfmt.Fprintf(os.Stderr, format, x)
สวิฟต์x = readLine()(2.x) print(x)(2.x) (1.x) println(x)
การใช้งาน JavaScript ในเว็บเบราว์เซอร์document.write(x)
JavaScript Active Server PagesResponse.Write(x)
JavaScript Windows Script Hostx = WScript.StdIn.Read(chars)หรือx = WScript.StdIn.ReadLine()WScript.Echo(x)หรือหรือWScript.StdOut.Write(x)WScript.StdOut.WriteLine(x)WScript.StdErr.Write(x)หรือWScript.StdErr.WriteLine(x)
ลิสปาร์กทั่วไป(setfx(read-line))(princ x)หรือ(format t format x)(princx*error-output*)หรือ(format*error-output*format x)
โครงการ ( R 6 RS ) (definex(read-line))(display x)หรือ(format#tformat x)(displayx(current-error-port))หรือ(format(current-error-port)format x)
ไอเอสลิสป์(setf x (read-line))(format(standard-output)format x)(format(error-output)format x)
ปาสคาลread(x);หรือreadln(x);write(x);หรือwriteln(x);write(stderr, x);หรือwriteln(stderr, x);
วิชวลเบสInput« promptxPrint xหรือ? xไม่มีข้อมูล
Visual Basic .NETx = Console.Read()หรือx = Console.ReadLine()Console.Write(«formatx)หรือConsole.WriteLine(«format, »x)Console.Error.Write(«format, »x)หรือConsole.Error.WriteLine(«format, »x)
โซโจx = StandardInputStream.Read()หรือx = StandardInputStreame.ReadLine()StandardOutputStream.Write(x)หรือStandardOutputStream.WriteLine(x)StdErr.Write(x)หรือStdErr.WriteLine(x)
ไพธอน 2.x x = raw_input(«prompt»)print xหรือsys.stdout.write(x)print>>sys.stderr,xหรือsys.stderr.write(x)
ไพธอน 3.x x = input(«prompt»)print(, end=""»)print(, end=""», file=sys.stderr)
เอส-ลังfgets (&x, stdin)fputs (x, stdout)fputs (x, stderr)
ฟอร์ทรานREAD(*,format) variable namesหรือ[e]READ(INPUT_UNIT,format) variable namesWRITE(*,format) expressionsหรือ[e]WRITE(OUTPUT_UNIT,format) expressionsWRITE(ERROR_UNIT,format) expressions[e]
ไปข้างหน้าbuffer length ACCEPT ( # chars read )KEY ( char )buffer length TYPEchar EMITไม่มีข้อมูล
พีพี$x = fgets(STDIN);หรือ$x = fscanf(STDIN, format);print x;หรือหรือechox;printf(format, x);fprintf(STDERR, format, x);
เพิร์ล$x = <>;หรือ$x = <STDIN>;print x;หรือprintfformat, x;print STDERR x;หรือprintf STDERR format, x;
ราคุ$x = $*IN.get;x.printหรือx.sayx.noteหรือหรือ$*ERR.print(x)$*ERR.say(x)
ทับทิมx = getsputs xหรือprintf(format, x)$stderr.puts(x)หรือ$stderr.printf(format, x)
วินโดวส์ พาวเวอร์เชลล์$x = Read-Host«« -Prompt» text»;หรือหรือ$x=[Console]::Read();$x=[Console]::ReadLine()x;หรือหรือWrite-Output x;echo xWrite-Error x
โอแคมล์let x = read_int ()หรือหรือlet str = read_line ()Scanf.scanfformat (fun x ... -> ...)print_int xหรือหรือprint_endline strPrintf.printfformat x ...prerr_int xหรือหรือprerr_endline strPrintf.eprintfformat x ...
เอฟ#letx=System.Console.ReadLine()printfformat x ...หรือprintfnformat x ...eprintfformat x ...หรือeprintfnformat x ...
มาตรฐาน MLvalstr=TextIO.inputLIneTextIO.stdInprint strTextIO.output(TextIO.stdErr, str)
ฮัสเคลล์ ( GHC ) x <- readLnหรือstr <- getLineprint xหรือputStrLn strhPrint stderr xหรือhPutStrLn stderr str
โคบอลACCEPT xDISPLAY x
  • นอกจากนี้ ALGOL 68 ยังมีการแปลงข้อมูลได้แก่read,write,get, และput.
  • ^bgets(x)และอ่านข้อความที่ไม่ได้จัดรูปแบบจาก stdin ไม่แนะนำให้ใช้ getsfgets(x, length, stdin)
  • ^cputs(x)และfputs(x, stdout)เขียนข้อความที่ไม่มีการจัดรูปแบบไปยัง stdout
  • ^dfputs(x, stderr)เขียนข้อความที่ไม่มีการจัดรูปแบบไปยัง stderr
  • ^e INPUT_UNIT, OUTPUT_UNIT, ERROR_UNITถูกกำหนดไว้ในโมดูลISO_FORTRAN_ENV [ 15 ]
ค่าอาร์กิวเมนต์ การโต้แย้งนับคะแนน ชื่อโปรแกรม / ชื่อสคริปต์
อาดา[ 1 ]Argument (n)Argument_CountCommand_Name
ซี ( ซี99 ) argv[n]argcข้อโต้แย้งแรก
ออบเจกทีฟซี
ซี++
ซี#args[n]args.LengthAssembly.GetEntryAssembly().Location;
ชวาargs.length
ดีข้อโต้แย้งแรก
คริสตัลARGV[n]ARGV.sizePROGRAM_NAME
การใช้งานJavaScript ใน Windows Script HostWScript.Arguments(n)WScript.Arguments.lengthWScript.ScriptNameหรือWScript.ScriptFullName
ไปos.Args[n]len(os.Args)ข้อโต้แย้งแรก
สนิม[a]std::env::args().nth(n)std::env::args_os().nth(n)std::env::args().count()std::env::args_os().count()std::env::args().next()std::env::args_os().next()
สวิฟต์Process.arguments[n]หรือProcess.unsafeArgv[n]Process.arguments.countหรือProcess.argcข้อโต้แย้งแรก
ลิสปาร์กทั่วไป? ? ?
โครงการ ( R 6 RS ) (list-ref(command-line)n)(length(command-line))ข้อโต้แย้งแรก
ไอเอสลิสป์ไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
ปาสคาลParamStr(n)ParamCountข้อโต้แย้งแรก
วิชวลเบสCommand[ข]ไม่มีข้อมูลApp.Path
Visual Basic .NETCmdArgs(n)CmdArgs.Length[Assembly].GetEntryAssembly().Location
โซโจSystem.CommandLine(การแยกวิเคราะห์สตริง) Application.ExecutableFile.Name
ไพธอนsys.argv[n]len(sys.argv)ข้อโต้แย้งแรก
เอส-ลัง__argv[n]__argcข้อโต้แย้งแรก
ฟอร์ทรานDO i = 1,argc  CALL GET_COMMAND_ARGUMENT (i,argv(i))ENDDOargc = COMMAND_ARGUMENT_COUNT ()CALL GET_COMMAND_ARGUMENT (0,progname)
พีพี$argv[n]$argcข้อโต้แย้งแรก
เปลือกหอย$n ($1, $2, $3, ...)$@(ข้อโต้แย้งทั้งหมด) $#$0
เพิร์ล$ARGV[n]scalar(@ARGV)$0
ราคุ@*ARGS[n]@*ARGS.elems$PROGRAM_NAME
ทับทิมARGV[n]ARGV.size$0
วินโดวส์ พาวเวอร์เชลล์$args[n]$args.Length$MyInvocation.MyCommand.Name
โอแคมล์Sys.argv.(n)Array.length Sys.argvข้อโต้แย้งแรก
เอฟ#args.[n]args.LengthAssembly.GetEntryAssembly().Location
มาตรฐาน MLList.nth(CommandLine.arguments(),n)length(CommandLine.arguments())CommandLine.name()
ฮัสเคลล์ ( GHC ) do{args<-System.getArgs;returnlengthargs!!n} do{args<-System.getArgs;returnlengthargs} System.getProgName
โคบอล[ค]ไม่มีข้อมูล
  • ^aใน Rust ฟังก์ชันนี้std::env::argsจะstd::env::args_osส่งคืนตัววนซ้ำstd::env::Argsและstd::env::ArgsOsตามลำดับArgsฟังก์ชันนี้จะแปลงอาร์กิวเมนต์แต่ละตัวเป็นStringและจะเกิดข้อผิดพลาดหากพบอาร์กิวเมนต์ที่ไม่สามารถแปลงเป็นUTF-8ได้ArgsOsฟังก์ชันนี้จะส่งคืนการแสดงผลแบบไม่สูญเสียข้อมูลของสตริงดิบจากระบบปฏิบัติการ (std::ffi::OsString) ซึ่งอาจเป็น UTF-8 ที่ไม่ถูกต้อง
  • ใน Visual Basic นั้นอาร์กิวเมนต์บรรทัดคำสั่งจะไม่ถูกแยกออกจากกัน การแยกอาร์กิวเมนต์เหล่านั้นต้องใช้ฟังก์ชันsplitSplit(string)
  • มาตรฐาน COBOL ไม่ได้ระบุวิธีการใด ๆ ในการเข้าถึงอาร์กิวเมนต์จากบรรทัดคำสั่ง แต่ส่วนขยายคอมไพเลอร์ทั่วไปที่ ใช้ในการเข้าถึงอาร์กิวเมนต์เหล่านี้ ได้แก่ การกำหนดพารามิเตอร์สำหรับโปรแกรมหลัก หรือการใช้ACCEPTคำสั่งต่างๆ

การดำเนินการตามคำสั่ง

คำสั่งเชลล์ ดำเนินการโปรแกรม แทนที่โปรแกรมปัจจุบันด้วยโปรแกรมที่เรียกใช้งานใหม่
อาดา[ 1 ]ไม่ได้ เป็นส่วนหนึ่งของมาตรฐานภาษา โดยทั่วไปจะทำผ่านแพ็กเกจที่คอมไพเลอร์จัดเตรียมไว้ หรือผ่านการเชื่อมต่อกับ C หรือPOSIX [ 16 ]
ซีsystem("command");execl(path, args);หรือexecv(path, arglist);
ซี++
ออบเจกทีฟซี[NSTasklaunchedTaskWithLaunchPath:(NSString*)patharguments:(NSArray*)arguments];
ซี#System.Diagnostics.Process.Start(path, argstring);
เอฟ#
คริสตัล`command`

หรือ Process.run command

Process.run path, argsProcess.exec path, args
ไปexec.Run(path, argv, envv, dir, exec.DevNull, exec.DevNull, exec.DevNull)os.Exec(path, argv, envv)
วิชวลเบสInteraction.Shell(command «, WindowStyle» «, isWaitOnReturn»)
Visual Basic .NETMicrosoft.VisualBasic.Interaction.Shell(command «, WindowStyle» «, isWaitOnReturn»)System.Diagnostics.Process.Start(path, argstring)
โซโจShell.Execute(command «, Parameters»)FolderItem.Launch(parameters, activate)ไม่มีข้อมูล
ดีstd.process.system("command");std.process.execv(path, arglist);
ชวาRuntime.exec(command);หรือnew ProcessBuilder(command).start();
การใช้งานJavaScript ใน Windows Script HostWScript.CreateObject("WScript.Shell").Run(command «, WindowStyle» «, isWaitOnReturn»);WshShell.Exec(command)
ลิสปาร์กทั่วไป(uiop:run-program command)
โครงการ(system command)
ไอเอสลิสป์ไม่มีข้อมูลไม่มีข้อมูลไม่มีข้อมูล
ปาสคาลsystem(command);
โอแคมล์Sys.command command, Unix.open_process_full command env (stdout, stdin, stderr),...Unix.create_process prog args new_stdin new_stdout new_stderr, ...Unix.execv prog argsหรือUnix.execve prog args env
มาตรฐาน MLOS.Process.system commandUnix.execute (path, args)Posix.Process.exec (path, args)
ฮัสเคลล์ ( GHC ) System.system commandSystem.Process.runProcess path args ...Posix.Process.executeFile path True args ...
เพิร์ลsystem(command)หรือหรือ$output = `command`$output = qx(command)exec(path, args)
ทับทิมsystem(command)หรือoutput = `command`exec(path, args)
พีพีsystem(command)หรือหรือหรือ$output = `command`exec(command)passthru(command)
ไพธอนos.system(command)หรือsubprocess.Popen(command)subprocess.call(["program", "arg1", "arg2", ...])os.execv(path, args)
เอส-ลังsystem(command)
ฟอร์ทรานCALL EXECUTE_COMMAND_LINE (COMMAND «, WAIT» «, EXITSTAT» «, CMDSTAT» «, CMDMSG»)[ก]
วินโดวส์ พาวเวอร์เชลล์[Diagnostics.Process]::Start(command)«Invoke-Item »program arg1 arg2 ...
เปลือกหอยoutput=`command`หรือoutput=$(command)program arg1 arg2 ...

^a Fortran 2008 หรือใหม่กว่า [ 17 ]

ดูเพิ่มเติม

ดึงข้อมูลมาจาก " https://en.wikipedia.org/w/index.php?title=Comparison_of_programming_languages_(basic_instructions)&oldid=1349415225 "

สรุปเนื้อหา

ข้อมูลสำคัญจากบทความ

ข้อมูลสำคัญเกี่ยวกับ การเปรียบเทียบภาษาโปรแกรม (คำสั่งพื้นฐาน)

บทความนี้เปรียบเทียบ ภาษาโปรแกรมจำนวนมากโดยแสดงตารางประเภทข้อมูลไวยากรณ์การแสดงนิพจน์ คำสั่งและการประกาศตัวแปรรวมถึงส่วนต่อประสานระบบปฏิบัติการทั่วไปบางส่วน

หลักเกณฑ์ของบทความนี้

โดยทั่วไป `var` , `var` หรือ `var` เป็นวิธีแสดงชื่อตัวแปรหรือค่าที่ไม่ใช่ค่าตัวอักษรที่ผู้อ่านต้องตีความ ส่วนที่เหลือเป็นโค้ดตัวอักษร เครื่องหมาย ` guillemets` ( « และ » ) ใช้สำหรับล้อมรอบส่วนที่ไม่จำเป็น ` ` Tab ↹ แสดงถึงการเยื้องที่จำเป็น (ช่องว่าง)

จำนวนเต็ม

8 บิต ( ไบต์ ) 16 บิต ( จำนวนเต็มสั้น ) 32 บิต 64 บิต ( จำนวนเต็มยาว ) ขนาดคำ แม่นยำตามอำเภอใจ ( บิ๊กนัม ) ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น ลงชื่อ ไม่มีลายเซ็น อาดา [ 1 ] range - 2 ** 7 .. 2 ** 7 - 1 [จ] range 0 .

จุดลอยตัว

ความแม่นยำเดี่ยว ความแม่นยำสองเท่า ความแม่นยำอื่นๆ ขึ้นอยู่กับโปรเซสเซอร์ อาดา [ 1 ] Float Long_Float — ไม่มีข้อมูล อัลโกล 68 real [ก] long real [ก] short real , long long real , เป็นต้น [ง] ซี float [ข] double long double [f] ซี++ (STL) ออบเจกทีฟซี ( โกโก้ )...