Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it support zero-based in for-loop? #274

Open
diuming opened this issue Mar 24, 2019 · 1 comment
Open

Does it support zero-based in for-loop? #274

diuming opened this issue Mar 24, 2019 · 1 comment

Comments

@diuming
Copy link

diuming commented Mar 24, 2019

Does it support zero-base in for-loop? thanks.

for-loop like swift

{% for idx in 0..<rows %}
...
{% endfor %}

forloop.first in nested for-loop?

{% for row in 0...9 %}
    do something in row
    {% for column in 0...9 %}
        do something in column

        /* How do I check the forloop.first is for row or column */ 
        {% if forloop.first %} 
              do something if `row` is first
        {% endif %}

    {% endfor %}
{% endfor %}

access array in nested for-loop with operators(+, -, *, /, %)?

{% for row in 0...9 %}
    {% for column in 0...9 %}
         {{ set index = row (+, -, *, /, %) column }}
         {{ array[index].attribute.value }}
    {% endfor %}
{% endfor %}
@diuming diuming changed the title Does it support zero-base in for-loop? Does it support zero-based in for-loop? Mar 25, 2019
@djbe
Copy link
Contributor

djbe commented Jul 30, 2022

  1. For loops like swift: yes, we support the range syntax.
  2. Nested for loops: this is now possible with Stencil 0.15, as long as you label your for loops
  3. operators: do you mean arithmetics? Then no (for now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants