Wednesday, 8 May 2024

PlantUML: preprocessing: procedures

PlantUML support procedures, where you can define once and reuse.

 

a.   Procedure names should start with a $

b.   Argument names should start with a $

c.    Procedures can call other procedures

 

procedures.txt

@startuml

!procedure $fib($arg)

	!$a = 0
	!$b = 1
	!$counter = 0
	!$fib = 0

	!while $counter < $arg
		#DarkSalmon:for the iteration $counter;
		#palegreen:a=$a, b=$b;

		!$fib = $a + $b
		!$a = $b
		!$b = $fib

		#palegreen:fib=$fib;

		!$counter = $counter + 1

	!endwhile

!endprocedure


start
	$fib(5)
end

@enduml

Above snippet shows what is happening in each iteration of fibonacci number calculation.

 


Previous                                                    Next                                                    Home

No comments:

Post a Comment