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(",");
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值