D
D
Danil Stolbov2020-05-05 15:48:55
PHP
Danil Stolbov, 2020-05-05 15:48:55

How to fix eternal recursion?

I want to make a function that every time, provided that the number is more than one hundred, will subtract 5 from it, but for some reason the browser goes into eternal recursion and simply subtracts 5, not even every time, but one-time, here is the construction itself:

function number($sum){
  if ($sum > 100) {
    echo $sum - 5;
    number($sum);
  }else return;
}
number(156);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-05-05
@danilst89

The eternal recursion happens because you never change the value$sum

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question