#python中, the While statement is used to loop the execution of a program that, under certain conditions, loops through a program to handle the same tasks that require repeated processing.
#while是 the "as type" loop structure.
I=1
While i<=20:
Print (i,end= "")
I+=1
Sum=0
I=1
While i<=100:
Sum+=i
I+=1
Else
Print ("\ n", sum)
Print ("0+2+...+100=", sum)
#从控制台录入一个数字, the factorial from 1 to the number;
result=1;i=1;numa=0;
Numa=int (Input ("Please enter a number:"))
While I<=numa:
Result*=i
I+=1
Else
Print ("Loop over!")
Print ("Result is:", result)
#使用while循环输出100以内的素数
x=2
While x<100:
n=2
While N<x-1:
If x%n==0:
Break
N+=1
Else
Print (x,end= "")
X+=1
Else
Print ("Loop End")
#输出100之内能被7整除的数
nnum=7;linecount=0;
While nnum<=100:
If nnum%7!=0:
Nnum+=1;
Continue
Else
Print (nnum,end= "")
lineCount+=1if lineCount==5: print() #单个print()换行; lineCount=0nNum+=1;
Else
Print ("\ n Loop End")
#使用while循环计算从1到100之和
Sum=0;i=1;
While i<=100:
Sum+=i;
I+=1;
Else
Print ("1+2+3+...+100=", sum);
Print ("\ n Program End")
the number of #从控制台录入打印 symbols.
row=0;i=0;
Row=int (Input ("Enter Number of lines:"));
While I<row:
Print ()
Print ("", end= "")
I+=1;
Else
Print ("\ n program run End")
#使用while循环和for循环嵌套. The Python language allows another loop body to be nested within one loop body.
#实例: Enter the number of rows and columns from the console to print the square.
I=1;j=1;
Numa=int (Input ("Enter Number of lines:"))
Numb=int (Input ("Please enter number of columns:"))
While I<=numa:
J=1
While J<=numb:
Print ("*", end= "")
J+=1
Print ()
I+=1
#使用while循环嵌套打印九九乘法口诀表;
I=1;j=1;
While i<=9:
J=1
While J<=i:
Print ("%d%d=%2d"% (J,i,ij), end= "")
J+=1
Print ()
I+=1
Else
Print ("\ n program run End")
#使用for循环打印九九乘法口诀表;
For I in Range (1,10):
For j in Range (1,10):
If j<=i:
Print ("%d%d=%2d"% (J,i,ij), end= "")
Else
Print ()
Else
Print ("\ n program run End");
Python while loop and double loop