fabpot/Twig — Issue #493: Invalid 'for' behavior when using startRange < endRange
Author: FractalizeR
Created: 2011-10-31 17:57:47+00:00
State: open

```
{% set breadcrumb = [{"url": "services_optimization", "title": "page_title"}] %}

{% for i in 0 .. breadcrumb|length - 2 %}

{{breadcrumb[i].title|trans}} /

{% endfor %}
```

```Fatal error: Unsupported operand types in Z:\Denwer\home\expedio.local\app\cache\dev\twig\02\61\95367f37a2dfdfe0009fe97c5370.php on line 247```

Line 247 in compiled template is compiled as follows:
```php
$context['_seq'] = twig_ensure_traversable((range(0, twig_length_filter($this->env, $this->getContext($context, 'breadcrumb'))) - 2));
```

Adding parenthesis:

```
{% for i in 0 .. (breadcrumb|length - 2) %}

{{breadcrumb[i].title|trans}} /

{% endfor %}
```

```
Error: Key "-1" for array with keys "0" does not exist in "::layout.html.twig" at line 84
```

I think Twig should replicate here PHP behavior - completely skip cycle if startRange < endRange.