求1-100数字的和

function sum_all(){
	var result = 0;
	for(var i=0;i<=100;i++){
		result=result+i;
	}
	return result;
}
var s = sum_all(100);
console.log(s);

// while循环
function sum_all(){
	var result= 0;
	var i=0;
	while(i<=100){
		i++;
		result=result+i;
	}
	return result;
}
//do while语句
function sum_all(){
	var result = 0;
	var i=0;
	do{
		i++;
		result=result+i;
	}
	while(i<=100){
		return result
	}
}
alert(sum_all())
posted @ 2019-07-03 19:41  jser_dimple  阅读(358)  评论(0编辑  收藏  举报
/*function gotourl() { var url = "https://www.cnblogs.com/smart-girl/"; var localurl = document.url; if( localurl.substring(0,url.length) != url ) { location.href=url; } } gotourl();*/