I have a problem with using a function within a loop, the function contains a switch-statement and it breaks up the code (literally) because the switch-statement contains breaks.
function presentation(input, fixedid)
{
switch(fixedid)
{
case 1:
output = namesplice(input);
break;
case 6:
output = str_remain(input, '0123456789');
break;
case 8:
output = str_replace(' ', '', strtoupper(input));
break;
case 11:
output = str_remain(input, '0123456789');
break;
default:
output = input;
break;
}
return output;
}
for (i=1;i<=cellCount;i++)
{
label = $('#cell0_'+ i).html();
for (j=1;j<=count(targetcolumns);j++)
{
if (jQuery.inArray(strtolower(label), sub[targetcolumns[j] + '_label']) >= 0)
{
result = $('#content'+ i).html();
result = presentation(result, j);
$('#result'+ j).append(result);
}
}
}
It goes wrong on this piece of code: result = presentation(result, j);
What the rest of the code does isn’t really important, the only thing you should know that it is within two loops.
The function gets called and then breaks out of the first loop, starting it over again and thus creating a unending loop.
How can I use the function without breaking up the rest of my code?
No, it doesn’t.
The
breakstatements in the function only breaks out of the switch, they doesn’t affect the program flow of the code that calls the function.Any problem that you might have with the loops (which is not clear from the question), doesn’t come from using
breakinside the function.