! Extra \else error
When I run the code below (via minimals), I get the following error, why? enter loop ! Extra \else. \@@plniterate ...\expandafter \@@plniterate \else \fi \myloop ...by 1 \ifnum \tempcnta >#1\else \repeat \fi \message {exit} l.16 \myloop{2008} Code: \newcount\startcnt \newcount\tempcnta \def\myloop#1{% \message{enter} \tempcnta=\the\startcnt% \loop \message{loop} \advance \tempcnta by 1 \ifnum\tempcnta>#1\else \repeat\fi \message{exit} } \starttext \startcnt=1800 \myloop{2008} \stoptext Thanks, Bart
Hi Bart
On Thu, Dec 11, 2008 at 9:50 PM, Bart C. Wise
When I run the code below (via minimals), I get the following error, why?
enter loop
! Extra \else.
\@@plniterate ...\expandafter \@@plniterate \else
\fi
\myloop ...by 1 \ifnum \tempcnta >#1\else \repeat
I think the loop structure should be: \loop ... \if... ... \repeat
\fi \message {exit}
l.16 \myloop{2008}
Code:
\newcount\startcnt
\newcount\tempcnta
\def\myloop#1{%
\message{enter}
\tempcnta=\the\startcnt%
\loop
\message{loop}
\advance \tempcnta by 1
\ifnum\tempcnta>#1\else \repeat\fi
\message{exit}
}
\starttext
\startcnt=1800
\myloop{2008}
\stoptext
Thanks,
Bart
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
-- Best Regards Chen ---------------------------------------------------------------- Zhi-chu Chen | Shanghai Synchrotron Radiation Facility No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China tel: 086 21 5955 3405 | zhichu.chen.googlepages.com | www.sinap.ac.cn ----------------------------------------------------------------
Zhichu Chen wrote:
Hi Bart
On Thu, Dec 11, 2008 at 9:50 PM, Bart C. Wise
wrote: When I run the code below (via minimals), I get the following error, why?
enter loop
! Extra \else.
\@@plniterate ...\expandafter \@@plniterate \else
\fi
\myloop ...by 1 \ifnum \tempcnta >#1\else \repeat
I think the loop structure should be: \loop ... \if... ... \repeat
just use: \doloop { \ifwhateveryoulike \exitloop \fi } ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Thursday 11 December 2008 07:17:51 am Hans Hagen wrote:
Zhichu Chen wrote:
Hi Bart
On Thu, Dec 11, 2008 at 9:50 PM, Bart C. Wise
wrote: When I run the code below (via minimals), I get the following error, why?
enter loop
! Extra \else.
\@@plniterate ...\expandafter \@@plniterate \else
\fi
\myloop ...by 1 \ifnum \tempcnta >#1\else \repeat
I think the loop structure should be: \loop ... \if... ... \repeat
just use:
\doloop {
\ifwhateveryoulike \exitloop \fi
Hans, Thanks, that works. But shouldn't the other one work as well? Is there something wrong with the syntax? Bart
Bart C. Wise wrote:
On Thursday 11 December 2008 07:17:51 am Hans Hagen wrote:
Zhichu Chen wrote:
Hi Bart
On Thu, Dec 11, 2008 at 9:50 PM, Bart C. Wise
wrote: When I run the code below (via minimals), I get the following error, why?
enter loop
! Extra \else.
\@@plniterate ...\expandafter \@@plniterate \else
\fi
\myloop ...by 1 \ifnum \tempcnta >#1\else \repeat I think the loop structure should be: \loop ... \if... ... \repeat just use:
\doloop {
\ifwhateveryoulike \exitloop \fi
Hans,
Thanks, that works. But shouldn't the other one work as well? Is there something wrong with the syntax?
you cannot use else in plain's loop macro; nor can you use it nested; it's just the way the plain loop macro is defined ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Thursday 11 December 2008 07:05:05 am Zhichu Chen wrote:
Hi Bart
On Thu, Dec 11, 2008 at 9:50 PM, Bart C. Wise
wrote: When I run the code below (via minimals), I get the following error, why?
enter loop
! Extra \else.
\@@plniterate ...\expandafter \@@plniterate \else
\fi
\myloop ...by 1 \ifnum \tempcnta >#1\else \repeat
I think the loop structure should be: \loop ... \if... ... \repeat
\fi \message {exit}
l.16 \myloop{2008}
Code:
\newcount\startcnt
\newcount\tempcnta
\def\myloop#1{%
\message{enter}
\tempcnta=\the\startcnt%
\loop
\message{loop}
\advance \tempcnta by 1
\ifnum\tempcnta>#1\else \repeat\fi
\message{exit}
}
\starttext
\startcnt=1800
\myloop{2008}
\stoptext
Zhichu, If I change the loop to be the following, I still get the same error: \def\myloop#1{% \tempcnta=\the\startcnt% \loop \advance \tempcnta by 1 \if\tempcnta=#1\else \repeat\fi } Bart
Hi Bart,
On Thu, Dec 11, 2008 at 10:21 PM, Bart C. Wise
If I change the loop to be the following, I still get the same error:
\def\myloop#1{% \tempcnta=\the\startcnt% \loop \advance \tempcnta by 1 \if\tempcnta=#1\else \repeat\fi }
Bart
No, you should define like: \def\myloop#1{% \tempcnta=\the\startcnt% \loop \advance \tempcnta by 1 \if\tempcnta<#1\repeat } No \else before \repeat in this case and no \fi outside the loop. Taking a look at the definition, you could find the following code (something like that, I can't remember clearly): \def\loop#1\repeat{\def\body{#1}\iterate} \def\iterate{something to do with \body} You can see there should not be an extra \else in the \body, and you don't need the \fi to enclose it. I don't know whether I've made my point clear. -- Best Regards Chen ---------------------------------------------------------------- Zhi-chu Chen | Shanghai Synchrotron Radiation Facility No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China tel: 086 21 5955 3405 | zhichu.chen.googlepages.com | www.sinap.ac.cn ----------------------------------------------------------------
On Thursday 11 December 2008 07:29:15 am Zhichu Chen wrote:
Hi Bart,
On Thu, Dec 11, 2008 at 10:21 PM, Bart C. Wise
wrote: If I change the loop to be the following, I still get the same error:
\def\myloop#1{% \tempcnta=\the\startcnt% \loop \advance \tempcnta by 1 \if\tempcnta=#1\else \repeat\fi }
Bart
No, you should define like:
\def\myloop#1{% \tempcnta=\the\startcnt% \loop \advance \tempcnta by 1 \if\tempcnta<#1\repeat }
No \else before \repeat in this case and no \fi outside the loop.
Taking a look at the definition, you could find the following code (something like that, I can't remember clearly):
\def\loop#1\repeat{\def\body{#1}\iterate} \def\iterate{something to do with \body}
You can see there should not be an extra \else in the \body, and you don't need the \fi to enclose it.
I don't know whether I've made my point clear.
Chen, Thanks. That makes sense now. However, when I take your code and run it, it only goes through 1 iteration of the loop and exits. I'm puzzled. Bart
Hi Bart,
On Thu, Dec 11, 2008 at 11:05 PM, Bart C. Wise
Chen,
Thanks. That makes sense now. However, when I take your code and run it, it only goes through 1 iteration of the loop and exits. I'm puzzled.
Bart
Really? 'cause when I run the following code =============================== \newcount\startcnt \newcount\tempcnta \def\myloop#1{% \message{enter} \tempcnta=\the\startcnt% \loop \message{loop} \advance \tempcnta by 1 \ifnum\tempcnta<#1 \repeat \message{exit}} \starttext \startcnt=1800 \myloop{2008} \stoptext =============================== I got =============================== systems : begin file test2 at line 14 enter loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop exit systems : end file test2 at line 20 ) =============================== which infers it works for me. Anyway, I recommand you take the advanced interface as Hans has suggested. It's easier to use, makes more sense and is more ConTeXt-like. -- Best Regards Chen ---------------------------------------------------------------- Zhi-chu Chen | Shanghai Synchrotron Radiation Facility No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China tel: 086 21 5955 3405 | zhichu.chen.googlepages.com | www.sinap.ac.cn ----------------------------------------------------------------
On Thursday 11 December 2008 08:28:40 am Zhichu Chen wrote:
Hi Bart,
On Thu, Dec 11, 2008 at 11:05 PM, Bart C. Wise
wrote: Chen,
Thanks. That makes sense now. However, when I take your code and run it, it only goes through 1 iteration of the loop and exits. I'm puzzled.
Bart
Really? 'cause when I run the following code =============================== \newcount\startcnt
\newcount\tempcnta
\def\myloop#1{% \message{enter} \tempcnta=\the\startcnt% \loop \message{loop} \advance \tempcnta by 1 \ifnum\tempcnta<#1 \repeat \message{exit}}
\starttext
\startcnt=1800
\myloop{2008}
\stoptext ===============================
I got
=============================== systems : begin file test2 at line 14 enter loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop loop exit systems : end file test2 at line 20 ) ===============================
which infers it works for me.
Anyway, I recommand you take the advanced interface as Hans has suggested. It's easier to use, makes more sense and is more ConTeXt-like.
Chen, Just to make sure I wasn't going too insane, I took your code and ran it. It worked. The difference is that in the previous email you sent, you had the code like this: \if\tempcnta<#1\repeat instead of this newer one: \ifnum\tempcnta<#1\repeat That's why it didn't work. Thanks to all! Bart
Am Thu, 11 Dec 2008 07:21:56 -0700 schrieb Bart C. Wise:
If I change the loop to be the following, I still get the same error:
\def\myloop#1{% \tempcnta=\the\startcnt% \loop \advance \tempcnta by 1 \if\tempcnta=#1\else \repeat\fi }
No, the \repeat take the place of the \fi. Also you should always end numbers with a space or a \relax to avoid trouble due to tex trying to expand the following commands in search for more numbers. \newcount\startcnt \newcount\tempcnta \def\myloop#1{% \tempcnta=\the\startcnt\relax% \loop \the\tempcnta, \advance \tempcnta by 1 \ifnum\tempcnta<#1 \repeat } \myloop{10} -- Ulrike Fischer
On Thursday 11 December 2008 08:10:38 am Ulrike Fischer wrote:
Am Thu, 11 Dec 2008 07:21:56 -0700 schrieb Bart C. Wise:
If I change the loop to be the following, I still get the same error:
\def\myloop#1{% \tempcnta=\the\startcnt% \loop \advance \tempcnta by 1 \if\tempcnta=#1\else \repeat\fi }
No, the \repeat take the place of the \fi. Also you should always end numbers with a space or a \relax to avoid trouble due to tex trying to expand the following commands in search for more numbers.
\newcount\startcnt \newcount\tempcnta
\def\myloop#1{% \tempcnta=\the\startcnt\relax% \loop \the\tempcnta, \advance \tempcnta by 1 \ifnum\tempcnta<#1 \repeat }
\myloop{10}
Excellent. Thanks Ulrike. This fixes the original problem! Bart
On Thu, 11 Dec 2008, Bart C. Wise wrote:
When I run the code below (via minimals), I get the following error, why?
\newcount\startcnt \newcount\tempcnta
\def\myloop#1{% \message{enter} \tempcnta=\the\startcnt% \loop \message{loop} \advance \tempcnta by 1 \ifnum\tempcnta>#1\else \repeat\fi \message{exit} }
\starttext \startcnt=1800 \myloop{2008} \stoptext
Do you know of \dostepwiserecurse{from}{to}{step}{body}. For example, \starttext \dostepwiserecurse{1800}{2008}{1}{We are at \recurselevel \endgraf} \stoptext Aditya
On Thursday 11 December 2008 08:07:01 am Aditya Mahajan wrote:
On Thu, 11 Dec 2008, Bart C. Wise wrote:
When I run the code below (via minimals), I get the following error, why?
\newcount\startcnt \newcount\tempcnta
\def\myloop#1{% \message{enter} \tempcnta=\the\startcnt% \loop \message{loop} \advance \tempcnta by 1 \ifnum\tempcnta>#1\else \repeat\fi \message{exit} }
\starttext \startcnt=1800 \myloop{2008} \stoptext
Do you know of \dostepwiserecurse{from}{to}{step}{body}. For example,
\starttext \dostepwiserecurse{1800}{2008}{1}{We are at \recurselevel \endgraf} \stoptext
Aditya, Hadn't thought of that one either. I'm taking a package from a LaTeX source and working on converting it. I'm trying to leave the original intact as much as possible. Unfortunately, in trying to leave it intact, I seem to be approaching the problem/solution rather myopically. Thanks for the hint. Bart
On Thu, 11 Dec 2008, Aditya Mahajan wrote:
On Thu, 11 Dec 2008, Bart C. Wise wrote:
When I run the code below (via minimals), I get the following error, why?
\newcount\startcnt \newcount\tempcnta
\def\myloop#1{% \message{enter} \tempcnta=\the\startcnt% \loop \message{loop} \advance \tempcnta by 1 \ifnum\tempcnta>#1\else \repeat\fi \message{exit} }
\starttext \startcnt=1800 \myloop{2008} \stoptext
Do you know of \dostepwiserecurse{from}{to}{step}{body}. For example,
\starttext \dostepwiserecurse{1800}{2008}{1}{We are at \recurselevel \endgraf} \stoptext
There is also doloop. Documentations from syst-ext.tex %D \macros %D {doloop,exitloop} %D %D Sometimes loops are not determined by counters, but by %D (a combinations of) conditions. We therefore implement a %D straightforward loop, which can only be left when we %D explictly exit it. Nesting is supported. First we present %D a more extensive alternative. %D %D \starttyping %D \doloop %D {Some kind of typesetting punishment \par %D \ifnum\pageno>100 \exitloop \fi} %D \stoptyping %D %D When needed, one can call for \type{\looplevel} and %D \type{\loopdepth}. [...] %D We don't have to declare new counters for \type{\looplevel} %D and \type{\loopdepth} because we can use \type{\recurselevel} %D and \type{\recursedepth}. (although I could not get recurselevel or looplevel to work) [...] %D The loop is executed at least once, so beware of situations %D like: %D %D \starttyping %D \doloop {\exitloop some commands} %D \stoptyping %D %D It's just a matter of putting the text into the \type{\if} %D statement that should be there anyway, like in: %D %D \starttyping %D \doloop {\ifwhatever \exitloop \else some commands\fi} %D \stoptyping %D %D You can also quit a loop immediately, by using \type %D {\exitloopnow} instead. Beware, this is more sensitive %D for conditional errors. So, you can write your example as (changed the stopping condition to add \else, just to illustrate that it works) \newcount\startcnt \newcount\tempcnta \def\myloop#1{% \message{enter} \tempcnta=\the\startcnt% \doloop{ \message{loop \the\tempcnta} \advance \tempcnta by 1 \ifnum\tempcnta<#1 \else \exitloop \fi} \message{exit} } \starttext \startcnt=1800 \myloop{2009} \stoptext Aditya
participants (6)
-
Aditya Mahajan
-
Bart C. Wise
-
Bart Wise
-
Hans Hagen
-
Ulrike Fischer
-
Zhichu Chen