endif

The endif command ends an if construct.

Syntax

endif

endif takes no arguments and stands alone on its line.

What it does

James ends the if it closes and reads on from the next line. A construct that is skipped is closed in the same way, and its nested if constructs are matched and counted.

When James applies it

By the command parser, when it is read. It is legal in any phase: Control, Part or Merge.

Rules James adds

  • Every if must close with its own endif in the file that opened it. If a file ends with an if still open, James reports it in that file.
  • An endif inside a when, for or while with no if of its own is reported as having no matching if (E0300).

Diagnostics

  • E0300: there is no open if for it to close.
  • E0309: the keyword shares its line with other input.
  • E0319: an if reaches the end of its file without an endif.

Example

The script tests/corpus/143-if-closed-in-parent-rejected/input.tg includes branch.inc, a file in the same directory, which make test runs. branch.inc holds an if and a title, with no endif:

if(1.eq.1)then
title inner

The script itself is tests/corpus/143-if-closed-in-parent-rejected/input.tg:

include branch.inc
endif

James prints this, which tests/corpus/143-if-closed-in-parent-rejected/expected.diag.txt holds:

branch.inc:1:1: error [E0319]: 'if' is not closed with 'endif'
input.tg:2:1: error [E0300]: endif with no matching if
james: 2 errors, 0 warnings

The endif on line 2 of the script is too late: the if belongs to branch.inc and must close there. James reports it in branch.inc, and then reports the endif as having no if.

See also

  • if: the construct this closes.
  • include: the file boundary an if cannot cross.

James 0.3.1.

This site uses Just the Docs, a documentation theme for Jekyll.