Can someone explain the logic behind this for loop… I just don’t get it on how it goes into the next element, that $from[$i], what is it doing?
$start = 2;
$path = array();
for (; $i != $start; $i = $from[$i])
$path[] = $i;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s not very clearly written. I assume
$iand$startare previously initialized.Basically, there is no for loop initialization. It continues until
$iequals$start. In the body,$iis appended to the$patharray. Before going to the next iteration,$iis set to the value of the$ikey in$from.So if the array looked like:
and
$iare$startare ‘foo’ and ‘goo’ respectively,$pathwill end up:If
$startis unreachable, it will loop forever.