Reputation: 2432
I am creating dynamic div, which is in for loop.
length = //some number from 1 to 10;
for(i=1; i<length; i++)
{
if(i > 5)
{
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
...
// Ignore further appending div's greater than 5 and show ...
}
else // number less than 5
{
<div></div>
<div></div>
<div></div>
}
}
Basically if my length
is more than 5, Append div upto 5 times, and how to ignore further appending showing ...
Upvotes: 0
Views: 270
Reputation: 101
If you only want the div to be append a maximum of 5 times, given any length you could do the following:
length = //some number from 1 to 10;
for(i=1; i<length; i++)
{
if(i > 5)
{
break;
}
<div></div>
}
U can check if the current number is greater than 5, if so break the loop and continue with any code that is beyong the loop.
Upvotes: 2