Monday 2 October 2023

Creating a while loop in a PlantUML activity diagram

Using while and end while keywords we can define a loop.

whileLoop.txt

@startuml

title "Print the file data to console"

!pragma useVerticalIf on

start

while (have more data?)
	:read next 1024 bytes from file to a buffer;
	:print buffer data to console;
endwhile

:Print 'finished reading the file';

stop

@enduml

 

Above snippet generate below diagram.

 


You can even provide labels for while, endwhile keywords.

 

whileLabel.txt

@startuml

title "Print the file data to console"

!pragma useVerticalIf on

start

while (have more data?) (yes)
	:read next 1024 bytes from file to a buffer;
	:print buffer data to console;
endwhile (no)

:Print 'finished reading the file';

stop

@enduml

 

Above snippet generate below diagram.

 


 

Previous                                                    Next                                                    Home

No comments:

Post a Comment