How to generate a series of same component at once?

0 votes
asked Jun 22, 2021 in Question / help by Vincent

Hi,

I want to duplicate the same component as follows:

@startuml

component [Adder] as 1

component [Adder] as 2

component [Adder] as 3

component [Adder] as 4

@enduml

Instead of writing 4 lines of code: component [Adder] as x, I try to use the procedure/while to generate four same components at once as follows.

@startuml

!procedure $foo($arg)

  !while $arg!=0

    component [Adder] as $arg;

    !$arg = $arg - 1

  !endwhile

!endprocedure

start

$foo(4)

end

@enduml

However, syntax error emerges. So are there some methods to implement this generator? 

1 Answer

0 votes
answered Jun 22, 2021 by The-Lu (74,900 points)

Hello V.,

For that, just suppress 'start'/''end' ; that is only for Activity diagram, but if you want a Component/Deployment diagram, we doesn't use of that, as:

@startuml
!procedure $foo($arg)
  !while $arg!=0
    component [Adder] as $arg
    !$arg = $arg - 1
  !endwhile
!endprocedure

$foo(4)
@enduml

Enjoy,
Regards,
Th.

commented Jun 22, 2021 by Vincent Xiao
Thanks very much! This helps a lot!
...