ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* ! Extra \else error
@ 2008-12-11 13:50 Bart C. Wise
  2008-12-11 14:05 ` Zhichu Chen
  2008-12-11 15:07 ` Aditya Mahajan
  0 siblings, 2 replies; 15+ messages in thread
From: Bart C. Wise @ 2008-12-11 13:50 UTC (permalink / raw)
  To: Context Mailing List


[-- Attachment #1.1: Type: text/plain, Size: 631 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 5788 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 13:50 ! Extra \else error Bart C. Wise
@ 2008-12-11 14:05 ` Zhichu Chen
  2008-12-11 14:17   ` Hans Hagen
  2008-12-11 14:21   ` Bart C. Wise
  2008-12-11 15:07 ` Aditya Mahajan
  1 sibling, 2 replies; 15+ messages in thread
From: Zhichu Chen @ 2008-12-11 14:05 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Bart

On Thu, Dec 11, 2008 at 9:50 PM, Bart C. Wise
<bntgcontext@wiseguysweb.com> 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
>
> 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
----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 14:05 ` Zhichu Chen
@ 2008-12-11 14:17   ` Hans Hagen
  2008-12-11 14:40     ` Bart C. Wise
  2008-12-11 14:21   ` Bart C. Wise
  1 sibling, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2008-12-11 14:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Zhichu Chen wrote:
> Hi Bart
> 
> On Thu, Dec 11, 2008 at 9:50 PM, Bart C. Wise
> <bntgcontext@wiseguysweb.com> 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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 14:05 ` Zhichu Chen
  2008-12-11 14:17   ` Hans Hagen
@ 2008-12-11 14:21   ` Bart C. Wise
  2008-12-11 14:29     ` Zhichu Chen
  2008-12-11 15:10     ` Ulrike Fischer
  1 sibling, 2 replies; 15+ messages in thread
From: Bart C. Wise @ 2008-12-11 14:21 UTC (permalink / raw)
  To: ntg-context; +Cc: Zhichu Chen

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
>
> <bntgcontext@wiseguysweb.com> 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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 14:21   ` Bart C. Wise
@ 2008-12-11 14:29     ` Zhichu Chen
  2008-12-11 15:05       ` Bart C. Wise
  2008-12-11 15:10     ` Ulrike Fischer
  1 sibling, 1 reply; 15+ messages in thread
From: Zhichu Chen @ 2008-12-11 14:29 UTC (permalink / raw)
  To: Bart C. Wise; +Cc: ntg-context

Hi Bart,

On Thu, Dec 11, 2008 at 10:21 PM, Bart C. Wise
<bntgcontext@wiseguysweb.com> 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.



-- 
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
----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 14:17   ` Hans Hagen
@ 2008-12-11 14:40     ` Bart C. Wise
  2008-12-11 15:03       ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Bart C. Wise @ 2008-12-11 14:40 UTC (permalink / raw)
  To: ntg-context; +Cc: Hans Hagen

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
> >
> > <bntgcontext@wiseguysweb.com> 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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 14:40     ` Bart C. Wise
@ 2008-12-11 15:03       ` Hans Hagen
  0 siblings, 0 replies; 15+ messages in thread
From: Hans Hagen @ 2008-12-11 15:03 UTC (permalink / raw)
  To: Bart C. Wise; +Cc: ntg-context

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
>>>
>>> <bntgcontext@wiseguysweb.com> 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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 14:29     ` Zhichu Chen
@ 2008-12-11 15:05       ` Bart C. Wise
  2008-12-11 15:28         ` Zhichu Chen
  0 siblings, 1 reply; 15+ messages in thread
From: Bart C. Wise @ 2008-12-11 15:05 UTC (permalink / raw)
  To: ntg-context

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
>
> <bntgcontext@wiseguysweb.com> 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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 13:50 ! Extra \else error Bart C. Wise
  2008-12-11 14:05 ` Zhichu Chen
@ 2008-12-11 15:07 ` Aditya Mahajan
  2008-12-11 15:17   ` Bart C. Wise
  2008-12-11 15:18   ` Aditya Mahajan
  1 sibling, 2 replies; 15+ messages in thread
From: Aditya Mahajan @ 2008-12-11 15:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 14:21   ` Bart C. Wise
  2008-12-11 14:29     ` Zhichu Chen
@ 2008-12-11 15:10     ` Ulrike Fischer
  2008-12-11 15:27       ` Bart Wise
  1 sibling, 1 reply; 15+ messages in thread
From: Ulrike Fischer @ 2008-12-11 15:10 UTC (permalink / raw)
  To: ntg-context

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 

___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 15:07 ` Aditya Mahajan
@ 2008-12-11 15:17   ` Bart C. Wise
  2008-12-11 15:18   ` Aditya Mahajan
  1 sibling, 0 replies; 15+ messages in thread
From: Bart C. Wise @ 2008-12-11 15:17 UTC (permalink / raw)
  To: ntg-context

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

___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 15:07 ` Aditya Mahajan
  2008-12-11 15:17   ` Bart C. Wise
@ 2008-12-11 15:18   ` Aditya Mahajan
  1 sibling, 0 replies; 15+ messages in thread
From: Aditya Mahajan @ 2008-12-11 15:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 15:10     ` Ulrike Fischer
@ 2008-12-11 15:27       ` Bart Wise
  0 siblings, 0 replies; 15+ messages in thread
From: Bart Wise @ 2008-12-11 15:27 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 15:05       ` Bart C. Wise
@ 2008-12-11 15:28         ` Zhichu Chen
  2008-12-11 15:39           ` Bart C. Wise
  0 siblings, 1 reply; 15+ messages in thread
From: Zhichu Chen @ 2008-12-11 15:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Bart,

On Thu, Dec 11, 2008 at 11:05 PM, Bart C. Wise
<bntgcontext@wiseguysweb.com> 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.

-- 
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
----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: ! Extra \else error
  2008-12-11 15:28         ` Zhichu Chen
@ 2008-12-11 15:39           ` Bart C. Wise
  0 siblings, 0 replies; 15+ messages in thread
From: Bart C. Wise @ 2008-12-11 15:39 UTC (permalink / raw)
  To: ntg-context

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
>
> <bntgcontext@wiseguysweb.com> 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
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-12-11 15:39 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-11 13:50 ! Extra \else error Bart C. Wise
2008-12-11 14:05 ` Zhichu Chen
2008-12-11 14:17   ` Hans Hagen
2008-12-11 14:40     ` Bart C. Wise
2008-12-11 15:03       ` Hans Hagen
2008-12-11 14:21   ` Bart C. Wise
2008-12-11 14:29     ` Zhichu Chen
2008-12-11 15:05       ` Bart C. Wise
2008-12-11 15:28         ` Zhichu Chen
2008-12-11 15:39           ` Bart C. Wise
2008-12-11 15:10     ` Ulrike Fischer
2008-12-11 15:27       ` Bart Wise
2008-12-11 15:07 ` Aditya Mahajan
2008-12-11 15:17   ` Bart C. Wise
2008-12-11 15:18   ` Aditya Mahajan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).