python-day6---while循環

# while 條件:
# 循環體的代碼1
# 循環體的代碼2
# 循環體的代碼3
# count=0
# while count < 10:
# print(count)
# count+=1

# while True: #死循環
# print('ok')

# while 1: #死循環
# print('ok')



#break:跳出本層循環
# count=0
# while count < 10:
# if count == 5:
# break
# print(count)
# count+=1

#continue:跳出本次循環
#0 1 2 3 7 8 9


# count=0
# while count < 10:
# if count >=4 and count <=6:
# count += 1
# continue
# print(count)
# count+=1


# OLDBOY_AGE=56
# while 1:
# age=input('猜一猜年齡>>: ')
# age=int(age)
#
# if age > OLDBOY_AGE:
# print('太大了')
# elif age < OLDBOY_AGE:
# print('過小了')
# else:
# print('猜對了')
# break



# OLDBOY_AGE=56
# count=1
# while count <= 3:
# age=input('猜一猜年齡>>: ')
# age=int(age)
#
# if age > OLDBOY_AGE:
# print('太大了')
# count+=1
# elif age < OLDBOY_AGE:
# print('過小了')
# count+=1
# else:
# print('猜對了')
# break





# OLDBOY_AGE=56
# count=1
# while True:
# if count > 3:
# print('您猜的次數超過限制')
# break
# age=input('猜一猜年齡>>: ')
# age=int(age)
#
# if age > OLDBOY_AGE:
# print('太大了')
# elif age < OLDBOY_AGE:
# print('過小了')
# else:
# print('猜對了')
# break
# count += 1







# while True:
# score = input('>>: ')
# score = int(score)
#
# if score >= 90:
# print('A')
# if score >= 80:
# print('B')
# if score >= 70:
# print('C')
# if score >= 60:
# print('D')
# if score < 60:
# print('E')







# OLDBOY_AGE=56
# count=0
# while True:
# if count > 2:
# break
# age=input('猜一猜年齡>>: ')
# age=int(age)
# if age > OLDBOY_AGE:
# print('太大了')
#
# if age < OLDBOY_AGE:
# print('過小了')
#
# if age == OLDBOY_AGE:
# print('猜對了')
# break
# count += 1




補充:
while True:
name=input('please input your name: ')
password=input('please input your password: ')

if name == 'egon' and password == '123':
print('login successfull')
while True:
cmd=input('>>: ')
if cmd == 'quit':
break
print('====>',cmd)
break


tag=True
while tag:
name=input('please input your name: ')
password=input('please input your password: ')

if name == 'egon' and password == '123':
print('login successfull')
while tag:
cmd=input('>>: ')
# if cmd == 'quit':
# tag=False
# continue
# print('====>',cmd)

if cmd == 'quit':
tag=False
else:
print('====>',cmd)



count=0
while count < 10:
if count == 3:
count+=1
continue
print(count)

count+=1
else: #最後執行
print('在最後執行,而且只有在while循環沒有被break打斷的狀況下才執行')


優化:
ount=0while count < 10:    if count == 3:        pass    else:        print(count)    count+=1
相關文章
相關標籤/搜索