Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: A doubt about infinite loop |
| Date | 2011-09-25 14:39 +0000 |
| Organization | Freie Universitaet Berlin |
| Message-ID | <9e8somF9h4U1@mid.uni-berlin.de> (permalink) |
| References | <57b6390c-d172-46a1-8607-fa9d9a917617@k15g2000yqd.googlegroups.com> |
Anshum Kocher <email.anshum@gmail.com> wrote:
> main()
int main( void )
> {
> unsigned int i=10;
> while(i-->=0)
> printf("%u ",i);
> int a[10];
> printf("%d",*a+1-*a+3);
> }
> This leads to an infinite loop
> main()
> {
> unsigned int i=10;
> while(i-=1>=0)
This could be written much simpler as
while ( i -= 1 )
(note that '-=' has a much lower precedence than '>='
and that '1 >= 0' evaluates to 1) and thus the loop
ends when 'i' has been decremented to 0. If you would
like the same effect as above you'd need
while ( ( i =- 1 ) >= 0 )
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A doubt about infinite loop Anshum Kocher <email.anshum@gmail.com> - 2011-09-25 06:32 -0700
Re: A doubt about infinite loop Harald van Dijk <truedfx@gmail.com> - 2011-09-25 07:32 -0700
Re: A doubt about infinite loop jt@toerring.de (Jens Thoms Toerring) - 2011-09-25 14:39 +0000
Re: A doubt about infinite loop Kleuskes & Moos <kleuske@somewhere.else.net> - 2011-09-25 15:03 +0000
Re: A doubt about infinite loop Seebs <usenet-nospam@seebs.net> - 2011-09-26 22:59 +0000
Re: A doubt about infinite loop Mark Bluemel <mark_bluemel@pobox.com> - 2011-09-27 08:40 +0100
Re: A doubt about infinite loop gazelle@shell.xmission.com (Kenny McCormack) - 2011-09-27 10:35 +0000
Re: A doubt about infinite loop Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-09-27 14:05 +0300
Re: A doubt about infinite loop gazelle@shell.xmission.com (Kenny McCormack) - 2011-09-27 12:35 +0000
Re: A doubt about infinite loop Nobody <nobody@nowhere.com> - 2011-09-27 19:10 +0100
Re: A doubt about infinite loop Seebs <usenet-nospam@seebs.net> - 2011-09-27 22:37 +0000
Re: A doubt about infinite loop Seebs <usenet-nospam@seebs.net> - 2011-09-27 22:37 +0000
csiph-web