Stop at the first over fifty · หยุดเมื่อเกินห้าสิบครั้งแรก
Stop at the first over fifty
n starts at 1. Keep adding 1 to it. As soon as n * n is more than 50, leave the loop with break. Print n afterwards.
break leaves the loop at once. ⚠️ It only works inside the loop, so the if that holds it must be indented under the while too — and the break indented once more, under the if. print(n) stays at the left, outside the loop, so it runs after the break.
หยุดที่ค่าแรกที่เกิน 50
n เริ่มที่ 1. ค้างเพิ่ม 1 เข้าไป. ทันทีที่ n * n > 50, ออกจากลูปด้วย break. พิมพ์ n ต่อจากนั้น
break ออกจากลูปทันที. ⚠️ มันทำงานได้เฉพาะ ภายใน ลูป ดังนั้น if ที่กักมันไว้ต้องจัดย่อใต้ while เช่นกัน — และ break จัดย่ออีกครั้ง ใต้ if. print(n) อยู่ทางซ้าย นอกลูป เพื่อให้รันหลัง break
n starts at 1. Keep adding 1 to it. As soon as n * n is more than 50, leave the loop with break. Print n afterwards. · n เริ่มที่ 1. ค้างเพิ่ม 1 เข้าไป. ทันทีที่ n * n > 50, ออกจากลูปด้วย break. พิมพ์ n ต่อจากนั้น
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่