I would like to format strings which contains codes like:
"function() { for(i=0;i<n;i++){ return i; }}"
The point is to put new lines to each ; except in the for loop, so the formatted output should be something like this:
function() {
for(i=0;i<n;i++){
return i;
}
}
Is there any written function for this, or I have to loop through the whole string?

{and}in your sample... Please provide a minimal reproducible example