@loop(): directive is a custom conditional
loop operator. It is being used to loop from a lower value to an higher value.
@loop($i: 5 -> 10):
List {{ $i }} <br>
@endloop;
@for(): directive. Internally, it translates to
@for($i=5; $i <= 10; $i++):
List {{ $i }} <br>
@endfor;
5 -> 10 means that the loop should run starting from the number 5 and ending at number 10.
The resulting response is shown below.
List 5
List 6
List 7
List 8
List 9
List 10
<?php
namespace spoova\mi\windows\Routes;
use Route;
class Home extends Route {
function __construct() {
// define only variable $list
$args = [ 'list' => [1, 2, 3, 4, 5] ];
self::call($this, [
// set method for accepted url: home
LASTURL() => 'home';
// parse variables to method
SELF::ARGS => $args
]);
}
function home($args) {
//compile template 'home' with variables
self::load('home' => compile($args));
}
}
$list variable
@loop($i: 0 -> (count($list) - 1)):
List {{ $list[$i] }} <br>
@endloop;
List 1
List 2
List 3
==,
>,
<. An example is shown below:
@loop($i: 5 < 10):
List {{ $i }} <br>
@endloop;
5
to number 9 since 5 is less than 10.
The result of this loop is shown below
List 5
List 6
List 7
List 8
List 9
10 to 5.
@loop($i: 5 <- 10):
List {{ $i }}
@endloop;
<- custom operator can also be replaced with the
<@ while the front <- operator
can be replaced with the @>
operator. An example is shown below:
@loop($i: 5 <@ 10):
List {{ $i }}
@endloop;
List 10
List 9
List 8
List 7
List 6
List 5