python java js循环比较

python中的循环跟java 和js的截然不同,所以做个比较 

python中

#   while 条件表达式 :
#       代码块
#   else :
#       代码块
i = 0
while i < 10 :
    i += 1
    print(i,'hello')
else :
    print('else中的代码块')

JavaScript

//定义一个变量,表示当前的钱数
var money = 1000;
var count = 0;
while(money < 5000){
    money *= 1.05;
	count++;
	}
//console.log(money);
console.log("一共需要"+count+"年");
//将prompt放入到一个循环中
			while(true){
				//score就是小明的期末成绩
				var score = prompt("请输入成绩(0-100):");
				//判断用户输入的值是否合法
				if(score >= 0 && score <= 100){
					//满足该条件则证明用户的输入合法,退出循环
					break;
				}
				alert("请输入有效的分数!!!");
			}

java

死循环

 while(true){
            System.out.println("循环中...");
        }
int x = 10;
        while( x < 20 ) {
            System.out.print("value of x : " + x );
            x++;
            System.out.print("\n");
        }
 int i = 0;
        do {
            i +=1;
        }while(i<10);

 for

死循环

for(;;){
           System.out.println("循环中.....");
       }
for(int x = 10; x < 20; x = x+1) {
            System.out.print("value of x : " + x );
            System.out.print("\n");
        }

增强for

int [] numbers = {10, 20, 30, 40, 50};
        for(int x : numbers ){
            System.out.print( x );
            System.out.print(",");
        }

猜你喜欢

转载自blog.csdn.net/dubo_csdn/article/details/84868896