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.

中文

在第一个超过五十处停下

n 从 1 开始,不断加 1。一旦 n * n 大于 50,就用 break 跳出循环。之后打印 n。

break 会立刻跳出循环。⚠️ 它只能写在循环里面,所以放着它的那个 if 也要缩进在 while 下面 —— break 再往里缩进一层,在 if 下面。print(n) 留在最左边,在循环外面,这样它会在跳出后才执行。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩