Automatically translated.View original post

☕️ Upwel Java EP.5! Command the computer to work repeatedly with the power of the Loop. 🔄

Halfway to the Java Code Learn Series! 🎉 Who's still together, send ☕️ emoji to rejoice.

Did your friends ever think that if we had to order a computer to print 100 glasses of "Make Coffee," would we have to type 100 times the same line of code? 😱

The answer is, "Don't do that!" Because in the world of programmers, we have a steel rule called DRY (Don't Repeat Yourself) or don't repeat anything, and this is the origin of the hero in this EP..."Loop (Reworking)" That's it! 🔄

Today we're going to get to know For Loop in a very simple way, and it's like ordering a computer to run around the field, where we have three tasks:

🟢 starting point (where to start)

🏁 Finish line (to which round)

👟 pace (plus how much is it?)

In a nutshell, you can scroll through the seven slides and ensure that the code that used to be long as a kite tail will be shortened to three lines immediately! ✨

🎮 Mini Challenge regularly EP.5:

(Stop by to see the full problem on page 6)

If we write a code for starting and finishing points like this:

for (int i = 1; i < = 3; i + +) {

System.out.println ("Hello Lemon8!");

}

Want to know...How many lines of "Hello Lemon8!" will be printed by the computer? 🤔

👇 Type your answer numbers into the comments! I'll add them to give my heart to all the talented people. 🎉

If you like Contender Upkill IT, easily understand this kind of painting, press ❤️, press Save 🔖, keep it to review the time to forget, and don't forget to click follow ➕. Definitely find fun on EP.6 (secretly spoiled: EP. We'll teach the computer to arrange the "locker" with Array!)

# Learn to write code # Programming # Java # Learn to write programs # Rookie writing code# Lemon8 edition coding # IT knowledge # Self-improvement # Programmer # Share IT Trick

4/19 Edited to

... Read moreการเรียนรู้ For Loop ใน Java เป็นก้าวสำคัญสำหรับผู้เริ่มต้นเขียนโปรแกรม เพราะมันช่วยให้เราสามารถสั่งงานที่เหมือนกันได้หลายครั้ง โดยไม่ต้องเขียนโค้ดซ้ำซาก ซึ่งช่วยประหยัดเวลาและลดข้อผิดพลาดได้มากมาย จากประสบการณ์ส่วนตัวที่ได้ลองเขียนโค้ด Java เพื่อสั่งให้เครื่องคอมพิวเตอร์ปริ้นท์ข้อความว่า “ทำกาแฟแก้วที่...” หลายๆ ครั้ง ผมพบว่าเมื่อใช้ For Loop โค้ดจะสั้นลงอย่างชัดเจนและอ่านง่ายมากขึ้น อย่างเช่นคำสั่ง for (int i = 1; i <= 100; i++) { System.out.println("ทำกาแฟแก้วที่" + i); } จะช่วยให้คอมพิวเตอร์ทำงานซ้ำ 100 รอบโดยอัตโนมัติ นอกจากนี้ การเข้าใจองค์ประกอบของ For Loop ทั้งจุดเริ่มต้น (start), เงื่อนไขจบ (end) และขั้นตอนการเพิ่มค่า (increment) ยังเป็นเรื่องจำเป็นมาก เพราะการตั้งค่าที่ไม่ถูกต้องอาจทำให้เกิดการวนลูปไม่มีที่สิ้นสุดหรือทำงานน้อยเกินไปได้ สำหรับคนที่สนใจ อย่าลืมลองทำ Mini Challenge ในบทความนี้ด้วยนะครับ เป็นการฝึกเขียนโค้ดลูปเพื่อพิมพ์คำว่า "Hello Lemon8!" 3 ครั้ง ซึ่งจะช่วยเพิ่มความมั่นใจในการใช้งาน For Loop ของคุณได้อย่างแน่นอน สุดท้ายนี้ การเรียนรู้เรื่อง Loop ยังเป็นพื้นฐานที่สำคัญสำหรับการทำงานกับโครงสร้างข้อมูลและอัลกอริทึมขั้นสูงในอนาคต เช่น การใช้ Array ที่จะสอนใน EP.6 ดังนั้นขอแนะนำให้ทุกคนตั้งใจฝึกฝนและลองเขียนโค้ดด้วยตัวเองบ่อยๆ เพื่อที่จะได้เข้าใจและใช้เทคนิคนี้ได้คล่องแคล่วมากขึ้นครับ