You could change your inner loop:
for j := 1 to i + 1 do
begin
if ( length(s) > n*2 ) then
begin
Break;
end;
str(i,c);
s:= s + c+',';
end;
Firstly, I'd advise you to always indent for clarity, so
for j := 1 to i + 1 do
begin
if ( length(s) > n*2 ) then
begin
Break;
end;
str(i,c);
s:= s + c+',';
end;
secondly, you only need begin and end to turn multiple statements into a single statement,
so since you've only got break in there, they're redundant - just use break directly:
for j := 1 to i + 1 do
begin
if ( length(s) > n*2 ) then Break;
str(i,c);
s:= s + c+',';
end;
Next, notice that you're recalculating that c an awful lot:
str(i,c);
suffix = c + ',';
for j := 1 to i + 1 do
begin
if ( length(s) > n*2 ) then Break;
s:= s + suffix;
end;
I'm not all that keen on using break because it feels suspiciously like a goto,
so maybe you could change this into a repeat ... until block:
str(i,c);
suffix = c + ',';
j := 1;
repeat
s := s + suffix;
j := j + 1;
until (j > i+1) or (length (s) > n*2);
(Notice that repeat and until come with an implicit begin and end so you don't need to type them.)
Now you might argue that I've reduced the clarity by making it less obvious that the loop just increments j.
I don't feel strongly in this case whatever you prefer, but if you're using break a lot, consider whether while or repeat are better for you.
Your condition about length (s) > n*2 puzzles me (and no-one else has put it in their version of your code).
You seem to want to cut it short for some reason. Are you sure? I'm not.
Below is a table of the output you get without the limit, then the first n*2 items of the output, and the first n*2
characters of the string, so you can check. What was the break statement designed to do?
n: 1
output: 1,1
length: 2
n*2: 2
first n*2 numbers: 1,1
first n*2 characters: 1,
n: 2
output: 1,1,2,2,2
length: 5
n*2: 4
first n*2 numbers: 1,1,2,2
first n*2 characters: 1,1,
n: 3
output: 1,1,2,2,2,3,3,3,3
length: 9
n*2: 6
first n*2 numbers: 1,1,2,2,2,3
first n*2 characters: 1,1,2,
n: 4
output: 1,1,2,2,2,3,3,3,3,4,4,4,4,4
length: 14
n*2: 8
first n*2 numbers: 1,1,2,2,2,3,3,3
first n*2 characters: 1,1,2,2,
n: 5
output: 1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5
length: 20
n*2: 10
first n*2 numbers: 1,1,2,2,2,3,3,3,3,4
first n*2 characters: 1,1,2,2,2,
n: 6
output: 1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6
length: 27
n*2: 12
first n*2 numbers: 1,1,2,2,2,3,3,3,3,4,4,4
first n*2 characters: 1,1,2,2,2,3,