1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

whileのelseブロック

1
Posted at
a = 0
b = 10
while a!=b:
	print("a!=b")
	a += 1
else:
	print("a==b")

pythonではwhile文にelseがくっついてることがある。
elseブロックの中身は、条件判定がfalseになった時(ループを抜ける時)に実行される。
ただし、break文とかで抜けた時は条件判定がfalseになったわけではないのでelseブロックは実行されない。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?