> For the complete documentation index, see [llms.txt](https://krootee.gitbook.io/python-turtle/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krootee.gitbook.io/python-turtle/3.example21-30/21.-3-loop.md).

# 21.รูป3เหลี่ยมซ้อนLoop

<figure><img src="https://1059722861-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWAMRQLhtfzfy8yv80Se5%2Fuploads%2FfVVDubX5BTfSHMCP6wX8%2F12.png?alt=media&amp;token=ef0a240b-e378-4ab3-bfe7-4eea860a4ad5" alt=""><figcaption></figcaption></figure>

```python
// Some code
import turtle	        #นำเข้าโมดูล turtle เพื่อใช้ในการวาดกราฟิก
t = turtle.Turtle()	#สร้างวัตถุ turtle ชื่อ t สำหรับใช้วาดกราฟิก
t.shape('turtle')	#กำหนดรูปร่างของหัวปากกาให้เป็นรูปเต่า
t.color('blue')	        #กำหนดสีของปากกาและกราฟิกเป็นสีน้ำเงิน
t.width(2)	        #กำหนดความหนาของเส้นที่ปากกาวาดเป็น 2 หน่วย
t.speed(10)	        #กำหนดความเร็วในการวาดกราฟิกเป็นระดับ 10 (ความเร็วสูง)
for _ in range(12):	#เริ่มลูปภายนอก วนซ้ำ 12 รอบ (สร้างรูปแบบซ้ำกัน 12 ครั้ง)
    for _ in range(3):	#เริ่มลูปภายในแรก วนซ้ำ 3 รอบ (วาดรูปสามเหลี่ยมเล็ก)
        t.fd(60)	#วาดเส้นตรงไปข้างหน้า 60 หน่วย
        t.rt(120)	#หมุนหัวปากกาทางขวา 120 องศา
    for _ in range(3):	#เริ่มลูปภายในที่สอง วนซ้ำ 3 รอบ (วาดรูปสามเหลี่ยมใหญ่)
        t.fd(100)	#วาดเส้นตรงไปข้างหน้า 100 หน่วย
        t.rt(120)	#หมุนหัวปากกาทางขวา 120 องศา
    t.lt(30)	        #หมุนหัวปากกาทางซ้าย 30 องศา

```

<figure><img src="https://1059722861-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWAMRQLhtfzfy8yv80Se5%2Fuploads%2FA5wlM5tgGglRckuSMHPq%2F12-1.png?alt=media&amp;token=cc9039b0-6fd1-45d4-a84f-716ae59923e5" alt=""><figcaption></figcaption></figure>
