Tuesday 7 May 2024

PlantUML: preprocessing: conditional statements

!if, !else, !elseif, !endif preprocessing constructs are used to define conditional statements.

 

conditions.txt

@startuml

!$studentMarks = 45

!if ($studentMarks < 35)
Server -> Client : Sorry, better luck next time
!else
Server -> Client : Hurray, you are passed in the exam
!endif

@enduml

 

Above snippet generate below diagram.

 


Let’s set the marks to 25 and regenerate the image.

 

!$studentMarks = 25

 

You will see below image.



Note

a.   As PlantUML do not have any special Boolean type, It considers integer 0 as false and any non-null number (as 1) or any string (as "1", or even "0") means true.

b.   You can use Boolean &&, || to combine the statements.

 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment