A
A
Azat Vadjipov2015-10-29 12:55:16
PHP
Azat Vadjipov, 2015-10-29 12:55:16

Who will explain recursion to a beginner?

c7256305a75447df8c2f63e829204d76.PNGsobsna, I know that in the 20th line there is a recursion. How to fix?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-10-29
@MrTweak

You ended up with an infinite loop and most likely you get a memory-related error there.
In the function, you need to specify the condition under which the recursion will be called:

function myCount ($i, $l = 5){
 if($i>=$l){
  echo $i.' <br>';
  $i++;
  myCount($i, $l);
 }else{
 echo 'Посчитал от '. $i . ' до '. '$l';
 }
}

myCount (1, 5);

M
Max, 2015-10-29
@MaxDukov

the function calls itself. And does nothing more. in the 20th line, you need to replace the PrintSecond call with something constructive.

V
Valentine, 2015-10-29
@gephaest

Remove call to itself in function body?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question