Statements

There are a number of statement types. The simplest is an expression statement, an expression that is not part of any other statement or expression. Expressions are defined more fully below. An expression statement is evaluated, and if its value is non-null (non-zero), it is assumed to be a string, and written to the program output file. If its value is null, nothing is written to the output file. For example, the expression

name(indi)
, where indi is a person, returns the person's name and writes it to the output file. On the other hand, the expression
set(n, nspouses(indi))
assigns the variable n the number of spouses that person indi has, but since set returns null, nothing is written to the output file.

The programming language includes if statements, while statements and procedure call statements, with the following formats:

if ([varb,] expr) { statements } 
	          [ elsif ([varb], expr) { statements } ]*
     	          [ else { statements } ]
	
while ([varb,] expr ) { statements }
call name ( args )

Square brackets indicate optional parts of the statement syntax. An if statement is executed by first evaluating the conditional expression in the if clause. If non-zero, the statements in the if clause are evaluated, and the rest of the if statement, if any, is ignored. If the value is zero, and there is an elsif clause following, the conditional in the elsif clause is evaluated, and if non-zero, the statements in that clause are executed. Conditionals are evaluated until one of them is non-zero, or until there are no more. If no conditional is non-zero, and if the if statement ends with an else clause, the statements in the else clause are executed. There are two forms of conditional expressions. If the conditional is a single expression, it is simply evaluated. If the conditional is a variable followed by an expression, the expression is evaluated and its value is assigned to the variable.

Note that if treats null strings as false, but empty strings as true. This has the benefit that

if(birth(indi))
will return true if there is a BIRT record, even if it is empty, but will return false if there is no BIRT record at all.

The while statement provides a looping mechanism. The conditional is evaluated, and if non-zero, the body of the loop is executed. After each iteration the expression is reevaluated; as long as it remains non-zero, the loop is repeated.

The call statement provides procedure calls. Name must match one of the procedures defined in the report program. Args is a list of argument expressions separated by commas. Recursion is allowed. When a call is executed, the values of its arguments are evaluated and used to initialize the procedure's parameters. The procedure is then executed. When the procedure completes, execution resumes with the first item after the call.

The report language also includes the following statement types:

include(string)
global(varb)
set(varb, expr)
continue()
break()
return([expr])

The include statement includes the contents of another file into the current file; its string expression is the name of another LifeLines program file. It is described in more detail below. The global statement must be used outside the scope of any procedure or function; it declares a variable to have global scope. The set statement is the assignment statement; the expression is evaluated, and its value is assigned to the variable. The continue statement jumps to the bottom of the current loop, but does not leave the loop. The break statement breaks out of the most closely nested loop. The return statement returns from the current procedure or function. Procedures have return statements without expressions; functions have return statements with expressions. None of these statements return a value, so none has a direct effect on program output.

In addition to these conventional statements, the report generator provides other iterator statements for looping through genealogical and other types of data. For example, the children statement iterates through the children of a family, the spouses statement iterates through the spouses of a person, and the families statement iterates through the families that a person is a spouse or parent in. These iterators and others are described in more detail later under the appropriate data types.