8.18/6/2018

If … ElseIf… EndIf (procedure)

This command structure can define up to two conditional blocks. Statements nested within the first block are executed only if the condition specified in the if statement returns true. If it returns false, the program branches to the first statement in the second block, if one has been defined using the elseif statement. Otherwise, control flows to the first statement following the endif command.

With PlanetPress Suite version 7.0, the elseif statement has been optimized to evaluate an argument, exactly like an if statement, and elseif statements from other programming languages. In order to complete the if...elseif...endif command structure, however, an else statement was also added, acting exactly like the previous, empty elseif. Note that the use of the else statement is strongly recommended, as it is optimized by comparison to the elseif statement. Also note that documents created with previous versions and using the if...elseif...endif structure will not be updated, for full backward compatibility.

Syntaxes

Prior to version 7.0

if( condition )

elseif()

endif()

Version 7.0 and above

if( condition1 )

...

elseif( condition2 )

...

else()

...

endif()

Argument

condition, condition1, condition2

Value of type Boolean to evaluate.

Code Sample Example

This example simply prints 5 lines of text, selecting fonts according to line numbers.

Example prior to version 7.0


define(&x,integer,1)
%Define loop variable and then set up loop
for(&x,1,1,5)
  if((&x mod 2)=0) 
    %If &x is an even number
    setstyle(&bluefont)
    %use the blue font
  elseif() %otherwise
    setstyle(&Default)
    %use the default font
  endif()
  show('Some text to display')
  %Display the text
  crlf()
  %Skip to the next line
endfor()

 


 

 

Example with version 7.0


define(&x, integer, inttostr(@(1, 1, 10)))

if(&x = 1)

setstyle(&bluefont)

elseif(&x = 2)

setstyle(&redfont)

else()

setstyle(&default)
endif()


 

 

Related topics: