for文 と break文 continue文
while文
some_list = [1, 2, 3, 4, 5]
i = 0
while i < len(some_list):
print(some_list[i])
i += 1
1
2
3
4
5
for文 イテレーター(反復処理)
リスト
some_list = [1, 2, 3, 4, 5]
for i in some_list:
print(i)
1
2
3
4
5
文字列
for s in 'abcde':
print(s)
a
b
c
d
e
for word in ['My', 'name', 'is', 'Mike']:
print(word)
My
name
is
Mike
break 強制終了
for word in ['My', 'name', 'is', 'Mike']:
if word == 'name':
break
print(word)
My
continue スキップ
for word in ['My', 'name', 'is', 'Mike']:
if word == 'name':
continue
print(word)
My
is
Mike
コメント