## 6.2.2.2 Logic and Iteration

GSP also supports logical and iterative tags out of the box. For logic there are if, else and elseif which support your typical branching scenarios:

    <g:if test="${session.role == 'admin'}">
       <%-- show administrative functions --%>
    </g:if>
    <g:else>
       <%-- show basic functions --%>
    </g:else>

For iteration GSP has the each and while tags:

    <g:each in="${[1,2,3]}" var="num">
       <p>Number ${num}</p>
    </g:each><g:set var="num" value="${1}" />
    <g:while test="${num < 5 }">
        <p>Number ${num++}</p>
    </g:while>