ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย MBMoo » 08/06/2020 7:12 pm

โค้ด: เลือกทั้งหมด

for i in range(1, 10): 
    if i == 1:
        print("*" * 10)
        pass
    b =10-i
    print(("*"*(10-i))+str(b) * i )

ผลลัพธ์
Python Knowledge-1.png
Python Knowledge-1.png (4.63 KiB) Viewed 754 times

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย jirawoot » 20/06/2019 1:37 pm

โค้ด: เลือกทั้งหมด

for a in 'training':
    print(a)
ผลลัพธ์
Selection_007.png
Selection_007.png (3.19 KiB) Viewed 1205 times

โค้ด: เลือกทั้งหมด

for a in 'mindphp.com':
    if a == '.':
        pass
    print(a)
ผลลัพธ์
Selection_008.png
Selection_008.png (3.39 KiB) Viewed 1205 times

โค้ด: เลือกทั้งหมด

for a in 'mindphp.com':
    if a == '.':
        break
    print(a)
ผลลัพธ์
Selection_009.png
Selection_009.png (6.04 KiB) Viewed 1205 times

โค้ด: เลือกทั้งหมด

for a in 'mindphp.com':
    if a == '.':
        continue
    print(a)
ผลลัพธ์
Selection_010.png
Selection_010.png (6.77 KiB) Viewed 1205 times

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย chatee supasand » 07/06/2019 4:30 pm

สุดยอดเลยครับเข้าใจเรื่องลูปมากๆครับ

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย rangsan » 03/05/2018 4:35 pm

For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โค้ด: เลือกทั้งหมด

ex_list = ['Roronoa Zolo','Luffy','Nami','Uusouf']
for i in ex_list: 
    print "Show List : ",i 
    if i=="Nami":
        break 
print "--------------------"

ผลการรันโค้ด
Forloop Statement.png
Forloop Statement.png (14.24 KiB) Viewed 1548 times
ศึกษาจาก : https://www.youtube.com/watch?v=imbVgL2 ... lzdKrpxsMM

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย Patcharanan.0399 » 19/04/2018 4:21 pm

โค้ด: เลือกทั้งหมด

for Hello in "World.com":
  if Hello == ".":
    continue
  print 'Last is : ',Hello

print("\nThank You")
ผลการรัน
ผลลัพธ์ For statement.jpg
ผลลัพธ์ For statement.jpg (6.74 KiB) Viewed 1555 times

ศึกษาจาก https://youtu.be/imbVgL2Vjvk

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย Jom07 » 24/01/2018 6:12 pm

ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

ตัวอย่าง For loop Statements

โค้ด: เลือกทั้งหมด

alist = ['Training', 'Python', 'mindphp']
for l in alist:
    print('alist ตัวล่าสุด', l)
print('--------------------')
ผลรัน

รูปภาพ

ศึกษาข้อมูลจาก :https://www.youtube.com/watch?v=imbVgL2 ... lzdKrpxsMM

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย Dive Demo » 03/02/2017 9:40 am

เข้าใจแล้วครับ ขอบคุณครับ

Re: ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย dawthana » 30/12/2016 10:17 am

สามารถศึกษาข้อมูลเพิ่มเติมได้ที่ https://www.mindphp.com/vdo-tutorial-pyt ... ments.html

ทำความรู้จักกับภาษา python (11) : For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)

โดย dawthana » 30/12/2016 10:15 am

For loop Statements (ฟอร์ ลูป สเตรดเม้นท์)
For loop คือการทำงานจนกว่าเงื่อนไขจะเป็นเท็จ เมื่อเท็จจึงจะออกจากลูป

รูปแบบการเขียน For loop Statements
for iterating_var in sequence :
  • statement(s)
  • ........................
  • ........................
โดย sequence คือการลำดับการทำงานอาจเป็นตัวแปร list (ลิส) หรือ string (สตริง) ก็ได้
ตัวอย่างการ For loop
loop1.png
loop1.png (32.17 KiB) Viewed 1639 times
การควบคุมลูปใน python
การควบคุมลูปหรือ Loop Control ในภาษา python (ไพทอน) จะมี 3 ประเภท คือ Pass , Break และ Continue
-Pass Statement (พาส สเตรดเม้นท์) คือการข้ามไปทำใน statement ตัวทัดไปแทน หรือเป็นการข้ามการทำงาน
ตัวอย่าง
looppass.png
looppass.png (35.06 KiB) Viewed 1639 times
-Break Statement (เบรค สเตรดเม้นท์) คือการหยุดลูปหรือออกจากลูปทันที โดยไม่ทำงานในลูปอีกต่อไป
ตัวอย่าง
loopbreak.png
loopbreak.png (30.25 KiB) Viewed 1639 times
-Continue Statement (คอนทินิว สเตรดเม้นท์) คือการออกจาก Block ที่ทำงานอยู่แล้วไปทำงานอันถัดไป
ตัวอย่าง
loopcon.png
loopcon.png (38.56 KiB) Viewed 1639 times
ศึกษาข้อมูลมาจาก https://www.youtube.com/watch?v=imbVgL2Vjvk

ข้างบน