Issue with twig loop.first loop.last contained in nested for statement
You should be able to access the outer loop.index etc using the loop.parent context. The Twig docs here should give you what you need.

EDIT: You might be getting strange results because the inner loop contains an if so depending on your conditions you might loop over the first item thus making your inner loop.first not work as expected. You can combine for with an if which might get you a bit closer, like this:

{% for thing in things if thing.isAvailable == true %}
{{-- Your inner stuff --}}
{% endfor %}


More info here.