I have some JSP code, which writes a tree representing hierachical data. This data is represented using nested layers.
In the JSP code there are many code snippets similar to the following code (which outputs as many closing div tags as is the numerical value of variable differenceAmount):
<jsp:scriptlet>
int differenceAmount = previousUserLevel - currentUserLevel;
for(int i=0;i<differenceAmount;i++){
</jsp:scriptlet>
</div>
<jsp:scriptlet>
}
</jsp:scriptlet>
Using scriptlets is rather inelegant, and reading the code is also not very easy at the first sight. In what way could the code be refactored to be more readable?