module 6 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

module 6

Can someone explain me step by step? What output results from the following code? function func($arg) { $result = 0; for($i=0; $i<$arg; $i++) { $result = $result + $i; } return $result; } echo func(5); //10 why? how?

7th Feb 2019, 11:56 PM
Safet Salkić
Safet Salkić - avatar
1 Answer
+ 4
Cycle 1: result = 0 + i(0) Cycle 2: result = 0 + i(1) Cycle 3: result = 1 + i(2) Cycle 4: result = 3 + i(3) Cycle 5 result = 6 + i(4) Result = 10
8th Feb 2019, 2:28 AM
Ole113
Ole113 - avatar