You can use arrays to achieve this. For example, using models of the Modelica standard library:
model ArrayDemo
parameter Integer n = 10 "Number of springs/masses";
Modelica.Mechanics.Translational.Sources.ConstantForce constantForce(f_constant=100);
Modelica.Mechanics.Translational.Components.Spring springs[n];
Modelica.Mechanics.Translational.Components.Mass masses[n];
Modelica.Mechanics.Translational.Components.Fixed fixed;
equation
connect(constantForce.flange, springs[1].flange_a);
for i in 1 : n - 1 loop
connect(springs[i].flange_b, masses[i].flange_a);
connect(masses[i].flange_b, springs[i + 1].flange_a);
end for;
connect(springs[n].flange_b, masses[n].flange_a);
connect(masses[n].flange_b, fixed.flange);
end ArrayDemo;
The idea is to declare the components using arrays and then connect them using for
loops.