Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Stop at the first over fifty · ⁨หยุดเมื่อเกินห้าสิบครั้งแรก⁩

English

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

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP