Question: It seems this is a general question of programming logic, as this issue seems to arise in my code regardless of what language it's coded in.

Basically I have 2 nested for loops, inside a for loop. The purpose of these for loops is to enumerate all possible values between two sets of values.

The problem with the code is that is the second set of values contains a 0 the values won't enumerate.

Say for example we want to enumerate all values between 0,0,0 and 1,1,1, this works perfectly fine, as each nested loop is processed. However is we try to calculate between 0,0,0 and 0,1,0 the loop will not continue on to the next loop, instead it will exit the loop and continue on to the rest of the code.

```
for ($i1=$coords1[0]; $i1<=$coords2[0]; $i1++) { //if $coords2[0] = 0 loop will fail
  for ($i2=$coords1[1]; $i2<=$coords2[1]; $i2++) { //if $coords2[1] = 0 loop will fail
    for ($i3=$coords1[2]; $i3<=$coords2[2]; $i3++) {//if $coords2[2] = 0 loop will fail
      $blocks.= $i1.",".$i2.",".$i3."|";
    }
  }
}
return $blocks;

```

Full code: [PHPFIDDLE](http://phpfiddle.org/main/code/in8-uaq)

Answer: 
Okay, to copy this over from our chat, I believe this is the solution: 

```
<?php
$set1 = explode(",", '1,0,1');
$set2 = explode(",", '1,1,0');

$allbetween = _allbetween($set1, $set2);
echo 'All Between: '.$allbetween.'<br/>';
$allcount = count(explode("|", $allbetween))-1;
echo 'Number Of Blocks: '.$allcount;

function _allbetween($coords1, $coords2) {
$blocks = "";

    for ($i=0; $i<=2; $i++) {
        if ($coords1[$i] > $coords2[$i]) {
            $tmp = $coords1[$i];
            $coords1[$i] = $coords2[$i];
            $coords2[$i] = $tmp;
        }
    }

for ($i1=$coords1[0]; $i1<=$coords2[0]; $i1++)
  {
        for ($i2=$coords1[1]; $i2<=$coords2[1]; $i2++)
            {
                for ($i3=$coords1[2]; $i3<=$coords2[2]; $i3++)
                    {
                        $blocks.= $i1.",".$i2.",".$i3."|";
                    }
            }
  }
return $blocks;
}
?>

```

[**DEMO HERE**](http://phpfiddle.org/main/code/cxu-a46)

The reason this works is that there is a swap loop at the beginning of your function, which swaps any of the three sets of values if the first is greater than the second. This ensures that all values "between" them can be calculated.

Edit: Fixing the demo link to the correct URL
I think you are searching for 

[GOTO function](http://www.php.net/manual/en/control-structures.goto.php)

And for the 

[Continue function](http://www.php.net/manual/en/control-structures.continue.php)