Home > database >  i want to print the integer always subtacted by 3
i want to print the integer always subtacted by 3

Time:02-25

i want to print like this 20 17 14 11 8. it should always subtract with 3

here is my code

let cv= 10
let sum=0

for(let i=20;i>5;i--){
    sum=i-3
    console.log(sum)
}

CodePudding user response:

Instead of reducing i by 1 in each iteration, reduce it by 3.

for(let i = 20; i > 5; i -= 3){
    console.log(i)
}

CodePudding user response:

Maybe this can help:

    for(let i=20;i>5;i=i-3){
      console.log(i)
        
    }

CodePudding user response:

Prints if sum >= 0.

let sum = 20
const subBy = 3

while(sum >= subBy){
  sum -= subBy
  console.log(sum)
}
  • Related