Reputation: 13357
Is there a way to make the current iteration repeat itself in a loop?
var repeated = false;
var total = 0;
for (var i = 0; i < 50; i++)
{
total += i;
if (i == 33 && !repeated)
{
repeated = true;
repeat; // imaginary
}
}
Upvotes: 2
Views: 2551
Reputation: 28528
You can try this, don't need to repeat:
var total = 0;
for (var i = 0; i < 50; i++)
{
total += i;
if (i == 33)
{
total += i;
}
}
Upvotes: 0
Reputation: 25555
Sure, just subtract 1 from i
.
var repeated = false;
var total = 0;
for (var i = 0; i < 50; i++)
{
total += i;
if (i == 33 && !repeated)
{
repeated = true;
i--;
}
}
Upvotes: 0