whlie 条件 #(当条件为真时) #break 强制终止循环:#continue 跳出当前循环:
print("num") #(输出num)
例:
输出1到100的偶数
num = 1
whlie num <= 100:
if num%2 == 0:
print("num")
num+=1
例:
yonghu = 1093166587
mima = 123456789
while True:
aa = int(input ("用户名:"))
bb = int(input ("密码:"))
if aa == yonghu:
print("欢迎登陆本页面")
break # break 终止循环;
else:
print("输入错误")
print (" ")
例:#嵌套循环:
height = int(input("height:"))
width = int(input("widtn:"))
user_height = 1
while user_height <= height:
user_width = 1
while user_width <=width:
print("#",end="")
user_width+=1
print("#")
user_height+=1