How to realize a small math problem with for loop?

topic: calculate the sum of n consecutive natural numbers starting from 1, and end when the sum value is just over 100, find n

Code:

var sum = 0;
var n = 0;
while(sum <= 100){
    nPP;
    sum +=n;
}
console.log(sum);
console.log(n);

question: how to implement this question with for loop?

Mar.06,2021

function a(count){
    var sum =0;
    for(var i=1;i<count;iPP){
        if(sum >count){
            console.log(i-1);
            break;
        }
        sum +=i;
    }
}
a(100);//10010010001000

var sum = 0;
for (var i = 0; sum <= 100; iPP) {
    sum += i;
}
console.log(sum);
console.log(i-1);

var sum = 0;
    for(var i = 0;i<=i;iPP){
        if(sum >= 100){
            break;
        }else{
            sum += i;
        }
    }
    console.log('i =' +(i-1));  //i = 14
    console.log('sum = '+sum); //sum = 105

function xx(){
    var sum=0;
    var n=0;
    for(;;){
        if(sum<=100){
            nPP;
            sum+=n;
            
            console.log(n);
        }else{
            console.log(n);
            return n;
        }
    }
}
xx();

var sum = 0;
for (var i = 1; sum <= 100; iPP) {
    sum += i;
}
console.log(sum);
console.log(i);

let sum = 0;
for(let i=0;i<=100;iPP){
    sum += i
}
console.log(sum)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e47da3-66609.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e47da3-66609.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?