Variables and DECLARE · ตัวแปรและการประกาศ DECLARE
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
English
A variable stores one value
- A variable has a name and holds one value you can change.
- The 2026 guide writes names in mixed case, starting with a letter:
NumberOfPlayersornumberOfPlayers. - These lessons use a capital first letter, the same shape as the guide's own examples.
ไทย
ตัวแปรเก็บค่าเพียงค่าเดียว
- ตัวแปร (variable) มีชื่อและเก็บค่าหนึ่งค่าที่คุณสามารถเปลี่ยนได้
- คู่มือปี 2026 เขียนชื่อแบบผสมตัวพิมพ์ใหญ่-เล็ก เริ่มด้วยตัวอักษร:
NumberOfPlayersหรือnumberOfPlayers - บทเรียนเหล่านี้ใช้ตัวอักษรแรกเป็นตัวพิมพ์ใหญ่ เหมือนกับตัวอย่างของคู่มือเอง
DECLARE Counter : INTEGER
Counter ← 0
Counter ← Counter + 1
OUTPUT Counter
English
DECLARE, then the arrow
DECLARE Counter : INTEGERcreates the variable and names its type.- The assignment operator is
←. It stores the value on the right. =is not how you store a value.=means "is equal to" inside a test.
ไทย
DECLARE ตามด้วยลูกศร
DECLARE Counter : INTEGERสร้างตัวแปรและระบุชนิดของตัวแปรนั้น- ตัวดำเนินการกำหนดค่าคือ
←它将值存储在右侧 =ไม่ใช่วิธีการเก็บค่า=หมายถึง "เท่ากับ" ภายในเงื่อนไขการทดสอบ
DECLARE Score : INTEGER
Score ← 40
Score ← Score + 2
OUTPUT Score
English
Watch out
- Declare a variable before you use it.
- An identifier starts with a letter. Digits may follow. The guide also allows
_.
ไทย
ระวัง
- Declare ตัวแปรก่อนนำไปใช้
- Identifier ต้องเริ่มด้วยตัวอักษร的数字可以跟随其后. คู่มือยังอนุญาตให้ใช้
_ได้ด้วย
English
Common mistakes
Counter ← 1stores 1.Counter = 1is not an assignment.- One variable holds one value. Assigning again replaces it.
ไทย
ข้อผิดพลาดที่พบบ่อย
Counter ← 1เก็บค่า 1Counter = 1ไม่ใช่การกำหนดค่า- ตัวแปรหนึ่งตัวเก็บค่าหนึ่งค่า การกำหนดค่าซ้ำจะแทนที่ค่าเดิม
English
Now you try
- Declare an integer, store a value with
←, and output it.
ไทย
ลองดูเลย
- Declare ตัวแปรจำนวนเต็ม, เก็บค่าด้วย
←, และแสดงผลมันออก
Declare Total as an INTEGER, store 8, and output it. · ประกาศ Total เป็น INTEGER, เก็บค่า 8, และแสดงผลลัพธ์
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Declare Counter as an INTEGER. Start it at 0, add 1, and output it. · ประกาศ Counter เป็น INTEGER. เริ่มต้นที่ 0, เพิ่ม 1, และแสดงผลลัพธ์
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่