Conditions and loops

If/Else

XSharper has the usual if/else construction, which has two notations.

The first XML-like notation, where else is included as a part of if element is a bit cumbersome. There is however an alternative syntax, with , yet there is no way to validate it against XSD schema.

 

There is a bunch of possible attributes in conditionals, isTrue, isFalse, isSet (if variable is set), isNotSet, isZero, isNotZero etc. Use xsharper /? if for more details.

While loop

XSharper has only a simple while loop.

 

Note the use of #lt# instead of <, to make the expression more readable.

While loop may define a maximum number of loops:

 

Actually, while can automatically assign its loop counter value to a variable specified in name attribute, making the code a bit shorter:

 

There is also a break statement, to exit a loop prematurely:

 

ForEach loop

forEach loop iterates through each element of a collection, XML document or a rowset.

Syntax is <foreach variable='${enumerable}'>

 

Or <foreach name='x' in='${enumerable}'> where name is optional (and defaults to empty string):

 

foreach can also parse rowsets: