# Define a \newif within a nested \ifdefined

The MWE below attemps to define a \newif within a \ifdefined. This works fine, except when the file is loaded the second time.

As it is below generates the following error message:

Incomplete \ifdefined; all text was ignored after line 1.

However if you comment out the \newif works as desired.

## Question:

How do I declare the \newif within the \ifdefined?

## MWE:

\documentclass{article}

\usepackage{filecontents}
\newcommand{\SomeCommand}{some command}%
\fi
\end{filecontents*}

\begin{document}
Lorem ipsum

\end{document}

-
\expandafter\newif\csname ifDTLnewboload\endcsname; but there are better ways. –  egreg Feb 3 '13 at 22:31

In order not to load a file twice, another method is preferable:

%%% MyHeader.tex
\expandafter\endinput
\fi

\newcommand{\SomeCommand}{some command}


If the file has already been loaded, the control sequence would be defined. So the conditional expands \endinput that stops reading the file. The \expandafter is just to finish the conditional. A different format would be

%%% MyHeader.tex

\newcommand{\SomeCommand}{some command}

because TeX always ends the line before \endinput does its work.
\expandafter\newif\csname ifDTLnewdbonload\endcsname

would work, because if TeX skips the \else branch, it will not "see" the already defined conditional.