Automatically translated.View original post

Loop loop while loop for loop 😍✨

Study a little a day. Develop yourself.

Today we learn Python in the loop part, while loop and for loop. When you write it, it is easy. Very convenient. Who hasn't tried to suggest to try it?

# coding # python # data # ai # learnonlemon8

2025/10/23 Edited to

... Read moreหลังจากลองเรียนเรื่อง Loop ใน Python แล้วรู้สึกว่าเป็นหัวข้อที่ “พอเข้าใจปุ๊บ ชีวิตง่ายขึ้นเยอะ” เพราะมันช่วยให้เราไม่ต้องเขียนโค้ดซ้ำๆ หลายบรรทัดค่ะ วันนี้เลยมาเสริมแบบสรุปใช้งานจริงให้ชัดๆ ระหว่าง for loop กับ while loop เผื่อใครกำลังงงเหมือนที่เราเคยงง 1) for loop เหมาะกับ “รู้จำนวนรอบ” หรือ “มีของให้วนอยู่แล้ว” ถ้าเรามี list/tuple/string หรืออยากวนตามช่วงตัวเลข for loop จะสะดวกมาก เช่น - วนเลข 0 ถึง 4 for i in range(5): print(i) - วนสมาชิกใน list names = ["A", "B", "C"] for n in names: print(n) ทริคที่ใช้บ่อย: ถ้าต้องการ “ลำดับ + ค่า” ให้ใช้ enumerate for idx, n in enumerate(names, start=1): print(idx, n) 2) while loop เหมาะกับ “ไม่รู้จำนวนรอบแน่นอน” และวนจนกว่าจะตรงเงื่อนไข เช่น วนจนกว่าค่าจะถึงเป้าหมาย หรือจนกว่าผู้ใช้จะพิมพ์คำว่า exit cmd = "" while cmd != "exit": cmd = input("type exit to stop: ") ข้อควรระวังของ while loop คือถ้าเงื่อนไขไม่เปลี่ยน จะกลายเป็น infinite loop (วนไม่จบ) ได้ง่ายๆ เวลาเขียนเราเลยชอบเช็กว่าในลูปมีการอัปเดตตัวแปรที่ใช้เป็นเงื่อนไขเสมอ 3) for loop vs while loop เลือกยังไงให้ไม่พลาด - ถ้ามี “ขอบเขตชัด” เช่น วน 10 รอบ, วนทุกข้อมูลใน list → ใช้ for loop - ถ้าเป็น “เงื่อนไข” เช่น วนจนกว่าจะเจอคำตอบที่ถูก, วนจนกว่าจะครบเงื่อนไข → ใช้ while loop 4) คำสั่งที่ทำให้ Loop คุมได้ขึ้น: break และ continue - break: ออกจากลูปทันทีเมื่อเจอเงื่อนไข for i in range(10): if i == 5: break print(i) - continue: ข้ามรอบนั้นไปทำรอบถัดไป for i in range(5): if i == 2: continue print(i) 5) ตัวอย่างเล็กๆ ที่เหมือนใช้งานจริง (สาย data / coding) สมมติอยากนับจำนวนค่าที่มากกว่า 50 ใน list scores = [10, 60, 80, 30] count = 0 for s in scores: if s > 50: count += 1 print(count) สรุปจากที่เรา Learn Python มา: ถ้าพึ่งเริ่ม แนะนำให้ลองเขียนทั้ง for loop และ while loop ด้วยโจทย์เล็กๆ วันละนิด (เช่น พิมพ์ดาว, รวมเลข, วนรายการ) จะจำได้เร็วมากค่ะ แล้วพอจับทางได้จะรู้สึกว่า loop เป็นเครื่องมือที่ “สะดวกและทรงพลัง” จริงๆ

Related posts

Alamo Canyon Loop-Oro Valley, AZ
Chasing sunshine and stunning views while hiking through the beautiful Arizona winter! ☀️🏞️ Nature's beauty never goes out of season. #goforahike #hikingarizona #azhikes #52hikechallenge
oh_happy_steph

oh_happy_steph

8 likes

A low-angle view of towering redwood trees reaching towards the sky, with sunlight filtering through their canopy. A dirt path and wooden fence are visible at the base of the trees, indicating a forest trail within the grove.
A brown sign for the Redwood Grove Loop Trail, detailing a 0.8-mile length, 30-foot elevation change, 1% typical grade, 8 ft width, and compact soil surface. A smaller sign below indicates no dogs allowed.
A view from inside a hollowed-out redwood tree, looking out onto a forest path with a wooden fence and other trees in the background. The dark, textured interior of the tree frames the scene.
HIKE The Redwood Grove Loop Trail in LA
I recently went to the Redwood Grove Loop Trail at Carbon Canyon Regional Park , and it was such a peaceful escape from the usual SoCal hustle. The trail is a 1.5-mile loop that’s super easy to walk, like no steep climbs or tricky terrain. It’s perfect for a quick nature fix, whether you're
itsmarytraveldiaries

itsmarytraveldiaries

33 likes

A person with short hair, neck tattoos, and ear gauges is shown crying with tears on their face, covering part of their face with a hand. Overlay text reads: "FROM THE HARDEST YEAR... TO AN EPIPHANY... TO CLIMBING OUT... I'M NOT DOING THIS ALONE." and "Vulnerable share 🙏".
Weird realization I had… I’m in a loop 🔁
Let me explain. Last December was rough. My husband’s work slowed way down, money got tight during the Holidays, my car died and sat in the shop for two weeks, and then his motorcycle accident flipped our world upside down. We walked into 2025 feeling like we’d scraped rock bottom — emotionally
Kerri | Mom Bestie💖

Kerri | Mom Bestie💖

2 likes

Any advice for this anger/depression loop?
I just got back from a 2 week solo trip across North America and while I learned a lot about myself. I’m a really angry and bitter person. And my depression is way worse than I ever realized. I’ve heard people say depression hides behind anger and bitterness, and now I think that’s exactly what’s h
Eliza

Eliza

12 likes

Loop Stitch Tutorial
#stitching #diycrochet #chain stitch #tutorials #crochet
KaraCrochetCreations

KaraCrochetCreations

362 likes

Learning about the Habit Loop
#booktok #pyschology #bookrecommendations #fyppp #mentalhealthmatters
Paige 🌱

Paige 🌱

7 likes

A lighthouse stands on a rocky coast at sunrise, with text '4 Day Trip Boston -> Maine Loop' overlayed, indicating a scenic road trip itinerary.
A picturesque waterfront town with colorful houses and a boat reflected in calm water, illustrating Day 1 of the trip: Boston, MA to Portland, ME.
A 'WELCOME TO KENNEBUNKPORT' sign overlooks a harbor with red buildings, marking Day 2 of the trip from Portland to Salem, MA.
📍4 Day Trip: Boston ➝ Maine Loop
📍 Best For: Scenic drives, lighthouses, lobster rolls, foliage hints Day 1: Boston, MA ➝ Portsmouth, NH ➝ Portland, ME (2 hr) * Morning: Explore Boston’s North End, grab a pastry at Mike’s Pastry * Afternoon: Stop in Portsmouth, NH (cute harbor town) * Evening: Arrive in Portland, explore Old
Kayla 🎀

Kayla 🎀

462 likes

Raging Loop Day One Edition!
Hey friends! I recently bought a new game and wanted to share it with you 🤍 I’ve always loved horror games, and some of my favorites have been in the visual novel/point-and-click genres (like Needy Streamer Overload and Doki Doki), so when I found Raging Loop, I knew I had to play it. It’s a
˚ʚ N e o n ɞ˚

˚ʚ N e o n ɞ˚

66 likes

Hands hold an open white case revealing two black earplugs. Overlaid text announces a review of viral earplugs, suggesting a personal trial of the product.
Hands display the earplug packaging, showing a portable case, various ear tip sizes, and a QR code for warranty. Overlaid text indicates the Quiet 2 version was chosen for noise cancellation.
Hands hold the earplug product box. Overlaid text lists the pros, such as noise cancelling and comfort, and cons, including lack of total silence and potential occlusion effect.
Trying out the viral Loop earplugs 🎧
As someone struggling with sensory input, I've been looking for ways to deal with the constant noise in daily life. I have a pair of noise cancelling headphones, but they can sometimes feel "too much", and I personally only like to wear them if I listen to music or podcasts. The Loop ea
addy 🌱

addy 🌱

17 likes

Loop Band/Resistance Band Core Exercises
You can use loop bands for so many different exercises! Plus, being that they’re so easy to travel with, you can basically get a workout in anywhere. Being postpartum I get a lot of questions on exercises for your core. Like most exercises I post, I love that these are challenging enough without
Alexis Nielsen

Alexis Nielsen

47 likes

One Stitch. Two Paths. Front Loop vs Back Loop
🧶 Front loop vs back loop can completely change a stitch. In Episode 13 of The Stitchery Files, we start with the technique… then the mystery unfolds. Come for the tutorial. Stay for the story. #crochet #crochettutorial #crochetstitches #fiberarts #thestitcheryfiles
Mostitching

Mostitching

38 likes

An elevated train structure, identified as CTA Loop Tower 18, with a small building on top, stands above a street with a 'Lake St' sign in Chicago. The intricate metal framework supports the tracks, with city buildings visible in the background.
A silver Chicago 'L' train, displaying route '313', moves along a complex network of elevated tracks at a busy rail interlocking. The train's front shows red lights, with urban buildings in the background.
A wide view of the elevated CTA Loop Tower 18 structure and its small building, with a 'Lake St' sign visible. City buildings rise behind the tracks, and a patch of pink flowers lines the street below.
CTA’s Loop Tower 18 🚉
If you're into trains or just love those classic Chicago views, you have to check out CTA Loop Tower 18 . 🚉 I stopped by and was seriously amazed watching all the 'L' trains crisscrossing this crazy diamond-shaped junction right in the heart of the city. It’s actually the busiest rail
Andie

Andie

4 likes

An open lavender box displays a round light gray Loop earplug case and various sized ear tips (XS, S, L). Text overlay indicates 'VOLUME' with a downward arrow, suggesting noise reduction.
A hand holds a small lavender box for Loop Quiet earplugs, featuring text 'BRING ON THE NOISE' and '-27 dB'. The background shows a car steering wheel. An overlay reads, 'SOME TIMES LIFE IS TOO NOISY, THESE HELP TO TURN DOWN THE VOLUME A BIT.'
An open lavender box reveals a round light gray Loop earplug case and ear tips. The box lid shows a QR code and 'SCAN FOR MORE'. A car steering wheel is in the background.
loop ear plugs 🙉
As a busy mama of 3 my hands are always full, sometimes it feels as if I can’t even think. I bought these a while back to test if it’ll help with my sanity. && it’s safe to say they definitely do work! These eat buds help drown out the noise without actually shutting everything out, it
keleiloa🌻

keleiloa🌻

32 likes

How To Loop Your Content
I love a good loop de loop in roller coasters and in social media content!! #contenttips #editingtutorials #loop
themuthership aka helen 💙

themuthership aka helen 💙

242 likes

Nice loop 🧡
#crochetwithme #easycrochet #crochettutorial #howtocrochet #stitchesbyfranci
Stitches By Franci 🧶

Stitches By Franci 🧶

112 likes

Motorbike loop of a lifetime
#motorized #motorcyles #motostyle #motortrend #fyp
Itsbikerhub 🎯

Itsbikerhub 🎯

171 likes

A finished friendship bracelet with a loop at one end, highlighted by a black circle, resting on a white textured surface. The text overlay reads 'How I made the loop on my bracelet!'.
Various embroidery threads are laid out on a brown carpet. The text describes cutting threads to size, choosing a loop color, and making it the longest string.
A single blue embroidery thread is separated and laid out next to a bundle of other threads on a brown carpet. The text explains that the blue string is chosen as the loop color and has excess length.
How I made the loop on my bracelet!
#lemon8diarychallenge please ignore the fact i was doing this on my floor lol, and also ignore the mess. However I tried my best to explain how I did the loop for my friendship bracelets. I’m not the best when explaining things so if this doesn’t help then I’d recommend watching a YouTube tutor
Tliyah Vlacos

Tliyah Vlacos

153 likes

Front, Back & 3rd Loop ~ Single Crochet
Today on The Daily Crochet we are exploring the possibilities of the Single Crochet using the Front Loop, Back Loop and 3rd Loop to create new stitches and decorative effects in our crochet projects. Personally, I love to frame a pattern row with one of these accents. The 3rd Loop only can create
Life in the Scrapatch

Life in the Scrapatch

61 likes

Two hands hold two vibrant, layered Fruit Loop Piña Coladas against a sunset ocean backdrop. Each drink is topped with whipped cream, Fruit Loops, sprinkles, and a pineapple slice, with blue squiggly lines drawn on the image.
This image displays the title 'Fruit Loop Piña Colada' and lists the ingredients for the drink, including white rum, coconut cream, pineapple juice, and Fruit Loops, set against a blurred background of the colorful drinks.
This image continues the recipe directions for the Fruit Loop Piña Colada, detailing how to divide and color the mixture, layer the drink, and prepare the cereal milk foam, overlaid on the blurred drink image.
Fruit Loop Piña Colada 🥣🍍
#fruitydrinkideas #summer #viral #fypシ #Lemon8 #lemon8challenge #bartending #drinks #drinksoflemon8 #fruity
Erika Lee

Erika Lee

596 likes

🌸Bloom loop bracelet DIY tutorial
just dropped a ✨flower bracelet tutorial✨ and it’s giving cottagecore vibes 🌸🧵 super easy, super cute, and v much a serve tbh 😌 grab some string & let’s get crafty 💗 #DIYBracelet #FlowerBracelet #HandmadeVibes #CraftTok
karolineknotbook

karolineknotbook

742 likes

Single Crochet In The Back Loop
Learn To Crochet: Single Crochet In The Back Loop This is a beginner stitch that places a standard single crochet into the back loop only of the stitch below it. This stitch creates a nice, stretchy fabric that is used for cuffs on sweaters and brims on beanies!! #Crochet #crocheting #c
Mountaine Pine Fiber Arts

Mountaine Pine Fiber Arts

25 likes

Overhead view of a jar of purple and blue swirled whipped body butter, labeled "Cloud Lemon Bodycare," surrounded by colorful Froot Loops cereal.
A jar of purple and blue swirled whipped body butter on a wooden surface, with a bowl of colorful Froot Loops cereal in the background.
A jar of "90s Kid Frooty Loops Whipped Body Butter" by Cloud Lemon Bodycare, showing its label and swirled purple and blue contents, with colorful cereal in the background.
90s Kid Body Butter 🫶 Froot Loop scent
90s Kid is a Froot Loops scented body butter. It smells amazing! We are finishing the final touches to our website. We plan to open our online shop at the end of this month. Grand opening announcements coming soon. Thank you for being patient with us while we complete our website 💖 #bodybutter
CloudLemonCo

CloudLemonCo

5 likes

OLD SCHOOL ITALIAN DELI IN WEST LOOP 🇮🇹
J.P. Graziano Grocery: 8.9/10 & $14.88 🇮🇹 Food: 9/10 Quality: 9.2/10 Service: 8.7/10 Price: 8.6/10 OVERALL: 8.9/10 901 W Randolph St, Chicago, IL 60607 #jpgraziano #chicagoitaliandeli #chicago
SERGELATO

SERGELATO

95 likes

Motorbike loop of a lifetime
#genxers #indianmotorcycle #pawpawlife My morning and night motorcycle life Decatur
Alabama Red

Alabama Red

77 likes

A stack of books by Ali Hazelwood, including 'Love, Theoretically,' 'The Love Hypothesis,' and 'Love on the Brain,' with a pink overlay asking 'Calling all readers!!!' and decorative hearts.
Are the loop ear plugs worth nearly $30?
My boyfriend’s a gamer (I am too) but on days I’d rather read instead of play video games I read in the living room with him while he’s on his game with his friends. And anyone who’s dating a gamer knows they can be loud which is OKAY! But I enjoy total silence while reading, but at the same time,
Kirsten Hedrick

Kirsten Hedrick

14 likes

A black cruiser motorcycle with chrome details is parked at night in front of a building displaying a Harley-Davidson banner and an American flag. The image features 'Good VIBES' text and sparkle overlays.
Motorbike loop of a lifetime
Billy Jack

Billy Jack

36 likes

Motorbike loop of a lifetime
Imagine your self riding on this 🔥✅ #surron #fyp #ride it #wheeliethebest #lemon8bookclub
Surron Bikes Shop

Surron Bikes Shop

153 likes

Get out of the paycheck to paycheck loop! 🫨💰
If you’re stuck in the paycheck to paycheck cycle, here’s some tips to break out of it. First you want to target your spending & your income. Cut back on anything that’s not needed. Do more research and use deals and coupons for what you are buying. Try to increase your income by getting a s
Kylie 💸🫶🏻

Kylie 💸🫶🏻

409 likes

The exterior of Graham Crackers Comics in Chicago, featuring a large 'COMICS' sign, superhero displays in the windows, and an 'OPEN' sign. Ads for East Loop Dental are visible on the windows above the store.
An interior view of Graham Crackers Comics, showing a large yellow 'COMICS' sign hanging from the ceiling, display cases filled with comics, and shelves packed with various titles and merchandise.
A long aisle inside Graham Crackers Comics, showcasing shelves filled with numerous comic books and graphic novels, with red 'MARVEL' signs visible on some sections.
Comic Heaven in the Heart of the Loop
I stumbled upon Graham Crackers Comics on a casual downtown walk, and I swear it felt like I unlocked a secret level in the city. If you’re a comic lover—or even just comic-curious—this spot is worth the detour (or the dedicated trip). The moment I walked in, I was met with walls lined from floo
Lily Brown

Lily Brown

7 likes

The Loop Trick That Changed My Heart Pillows! 🧶🫣
Quick tip for making your heart pillow loops small and consistent! ❤️ When I start my beginning chain, I hold the yarn tail gently in place with my stomach so I can pull each loop evenly as I go. It’s actually very similar to when you braid someone’s hair—you keep a little tension so everything st
holymolydane

holymolydane

58 likes

See more