sentinel control loops

Discussion in 'C Programming' started by shan, Oct 20, 2005.

  1. shan

    shan Guest

    Hi to everybody

    here is my simple doubt

    What is meant by sentinel control loops ?
     
    shan, Oct 20, 2005
    #1
    1. Advertising

  2. shan

    Guest

    Sentinel-controlled loops
    When an unknown number of data items are to be processed, some way to
    recognise the end of the data is needed.

    One solution is to define a sentinel value
    a unique value that indicates end-of-data
    it cannot be a value that could occur as data

    Code template:


    sentinel : constant := ???;

    loop
    read (item);
    exit when item = sentinel;

    process the item;

    end loop;


    Example: add integers that the user enters, up to but not including -1
    for end of data


    tot := 0;
    loop
    PUT("Enter an integer (-1 to exit): ");
    GET(j); SKIP_LINE;
    exit when (j = -1);
    tot := tot + j;
    end loop;

    -

    MistakenIdentity
     
    , Oct 20, 2005
    #2
    1. Advertising

  3. On 20 Oct 2005 02:28:47 -0700, in comp.lang.c , "shan"
    <> wrote:

    >Hi to everybody
    >
    >here is my simple doubt


    This isn't a doubt, its a question. For one thing, doubt is a verb...

    >What is meant by sentinel control loops ?


    loops where some sentinel value controls when you break out, or so I
    would think

    while(1)
    {
    int x = getchar();
    if (x=='a') break;
    }
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Oct 21, 2005
    #3
  4. Mark McIntyre <> writes:
    > On 20 Oct 2005 02:28:47 -0700, in comp.lang.c , "shan"
    > <> wrote:
    >>Hi to everybody
    >>
    >>here is my simple doubt

    >
    > This isn't a doubt, its a question. For one thing, doubt is a verb...


    I have my doubts about that.

    (Yes, doubt is a verb. It's also a noun. And yes, "question" is more
    appropriate in this context.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 21, 2005
    #4
  5. shan

    Ben Pfaff Guest

    Keith Thompson <> writes:

    > Mark McIntyre <> writes:
    >> On 20 Oct 2005 02:28:47 -0700, in comp.lang.c , "shan"
    >> <> wrote:
    >>>Hi to everybody
    >>>
    >>>here is my simple doubt

    >>
    >> This isn't a doubt, its a question. For one thing, doubt is a verb...

    >
    > I have my doubts about that.
    >
    > (Yes, doubt is a verb. It's also a noun. And yes, "question" is more
    > appropriate in this context.)


    "doubt" is Indian English for "question". I've had discussions
    with Indians at Stanford about this before.
    --
    int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
    \n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
    );while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p\
    );}return 0;}
     
    Ben Pfaff, Oct 21, 2005
    #5
  6. On Fri, 21 Oct 2005 01:43:13 GMT, in comp.lang.c , Keith Thompson
    <> wrote:

    >Mark McIntyre <> writes:
    >> On 20 Oct 2005 02:28:47 -0700, in comp.lang.c , "shan"
    >> <> wrote:
    >>>Hi to everybody
    >>>
    >>>here is my simple doubt

    >>
    >> This isn't a doubt, its a question. For one thing, doubt is a verb...

    >
    >I have my doubts about that.


    One could argue that the verb is "to have doubt" ...
    >
    >(Yes, doubt is a verb. It's also a noun.


    True.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Oct 22, 2005
    #6
  7. Mark McIntyre <> writes:
    > On Fri, 21 Oct 2005 01:43:13 GMT, in comp.lang.c , Keith Thompson
    > <> wrote:
    >>Mark McIntyre <> writes:
    >>> On 20 Oct 2005 02:28:47 -0700, in comp.lang.c , "shan"
    >>> <> wrote:
    >>>>Hi to everybody
    >>>>
    >>>>here is my simple doubt
    >>>
    >>> This isn't a doubt, its a question. For one thing, doubt is a verb...

    >>
    >>I have my doubts about that.

    >
    > One could argue that the verb is "to have doubt" ...
    >>
    >>(Yes, doubt is a verb. It's also a noun.

    >
    > True.


    Elsewhere in this thread, Ben Pfaff wrote:
    ] "doubt" is Indian English for "question". I've had discussions
    ] with Indians at Stanford about this before.
    which is certainly consistent with the usage we've seen.

    I suggest we accept the usage as a regional variant, just as we accept
    both American and British spellings. Once you know the idiom, there's
    no real ambiguity.

    And it will give us more time to flame ppl 4 stpd abbrvs.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 22, 2005
    #7
  8. Questions & Doubts (Was: Re: sentinel control loops)

    In article <>,
    Keith Thompson <> wrote:
    ....
    >Elsewhere in this thread, Ben Pfaff wrote:
    >] "doubt" is Indian English for "question". I've had discussions
    >] with Indians at Stanford about this before.
    >which is certainly consistent with the usage we've seen.
    >
    >I suggest we accept the usage as a regional variant, just as we accept
    >both American and British spellings. Once you know the idiom, there's
    >no real ambiguity.


    Note that, as verbs, "question" and "doubt" can be seen as synonyms.
    So, maybe that's why some see them that way as nouns.
     
    Kenny McCormack, Oct 22, 2005
    #8
  9. shan a écrit :
    > Hi to everybody
    >
    > here is my simple doubt
    >
    > What is meant by sentinel control loops ?
    >

    A good standard example of sentinel is the trailing 0 of a C-string:

    {
    char s[] = "Hello world";
    char *p = s;

    while (*p != 0)
    {
    putchar (*p);
    p++;
    }
    putchar ('\n');
    }

    --
    C is a sharp tool
     
    Emmanuel Delahaye, Oct 22, 2005
    #9
  10. On Sat, 22 Oct 2005 17:01:55 GMT, in comp.lang.c , Keith Thompson
    <> wrote:

    >
    >I suggest we accept the usage as a regional variant, just as we accept
    >both American and British spellings.


    Alternatively, one could take the opportunity to correct what seems
    mostly to be a misunderstanding. I work with many folks with
    subcontinental origins, and few if any of them make this mistake. If
    anything, it seems to be am americanism....

    >And it will give us more time to flame ppl 4 stpd abbrvs.


    oo r u kdin m8?
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Oct 23, 2005
    #10
  11. shan

    Ben Pfaff Guest

    Mark McIntyre <> writes:

    > On Sat, 22 Oct 2005 17:01:55 GMT, in comp.lang.c , Keith Thompson
    > <> wrote:
    >
    >>I suggest we accept the usage as a regional variant, just as we accept
    >>both American and British spellings.

    >
    > Alternatively, one could take the opportunity to correct what seems
    > mostly to be a misunderstanding. I work with many folks with
    > subcontinental origins, and few if any of them make this mistake. If
    > anything, it seems to be am americanism....


    That's strange--I've never run into anyone not from India who
    routinely calls a question a "doubt".
    --
    Ben Pfaff
    email:
    web: http://benpfaff.org
     
    Ben Pfaff, Oct 23, 2005
    #11
  12. Mark McIntyre <> writes:
    > On Sat, 22 Oct 2005 17:01:55 GMT, in comp.lang.c , Keith Thompson
    > <> wrote:
    >>I suggest we accept the usage as a regional variant, just as we accept
    >>both American and British spellings.

    >
    > Alternatively, one could take the opportunity to correct what seems
    > mostly to be a misunderstanding. I work with many folks with
    > subcontinental origins, and few if any of them make this mistake. If
    > anything, it seems to be am americanism....


    That assumes that it's a mistake. Ben Pfaff's statement seemed to
    imply that it's become more or less standard usage in Indian English,
    no more of a mistake than spelling "color" with a 'u'.

    I have little basis for judging one way or the other. Merriam
    Webster's Collegiate Dictionary doesn't show that "doubt" can mean
    "question", but it may not cover Indian usage.

    Whether "doubt" can legitimately mean "question" is a question for
    alt.usage.english. A quick search there shows a couple of threads on
    the subject; the consensus there seems to be that using "doubt" to
    mean "question" is incorrect. I'd be interested in seeing a more
    definitive answer.

    Either way, those of us who read comp.lang.c need to be aware that the
    word "doubt" is often used to mean "question", particularly (it seems)
    by posters from India. Conversely, posters would be well advised to
    use the word "question" to avoid any misunderstandings by those of us
    who speak American or British English.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 23, 2005
    #12
  13. Mark McIntyre <> writes:

    > On Sat, 22 Oct 2005 17:01:55 GMT, in comp.lang.c , Keith Thompson
    > <> wrote:
    >
    > >
    > >I suggest we accept the usage as a regional variant, just as we accept
    > >both American and British spellings.

    >
    > Alternatively, one could take the opportunity to correct what seems
    > mostly to be a misunderstanding. I work with many folks with
    > subcontinental origins, and few if any of them make this mistake. If
    > anything, it seems to be am americanism....


    If it really is incorrect to use the word "doubt" where most poeple
    would expect "question", wouldn't it be off topic and against the
    c.l.c culture to correct such usage here instead of pointing out
    the correct newsgroup for discussions about the English language? :)

    /Niklas Norrthon
     
    Niklas Norrthon, Oct 24, 2005
    #13
  14. On Sun, 23 Oct 2005 20:39:18 GMT, in comp.lang.c , Keith Thompson
    <> wrote:

    >Mark McIntyre <> writes:
    >> Alternatively, one could take the opportunity to correct what seems
    >> mostly to be a misunderstanding.

    >
    >That assumes that it's a mistake. Ben Pfaff's statement seemed to
    >imply that it's become more or less standard usage in Indian English,


    I was making two points
    1) I don't consider Ben's experience typical of the Indians I know.
    2) I don't think its a bad thing to help people learn better english.

    I'd always thought that the point of a human language was to
    communicate, and if common words are used unusually, then
    communication becomes tricky.

    To slip back into C for a moment, there's nothing actually *wrong*
    with naming all variables UPPERCASE and all macros in lowercase, or
    using macros such as #define P printf, or using the suffix sz to
    identify doubles. I suspect that we'd generally agree however that
    such usage was confusing, no matter how 'commonplace' it might be in
    the school or country from which the poster hailed.

    By the way I'd agree more with your thesis by the way if I'd not seen
    the same usage from many non-Indians in this group.

    >no more of a mistake than spelling "color" with a 'u'.


    Luckily we brits can keep our pants up without suspenders....

    >Either way, those of us who read comp.lang.c need to be aware that the
    >word "doubt" is often used to mean "question", particularly (it seems)
    >by posters from India. Conversely, posters would be well advised to
    >use the word "question" to avoid any misunderstandings by those of us
    >who speak American or British English.


    Absolutely.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Oct 24, 2005
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. d.j.

    sentinel

    d.j., Apr 22, 2004, in forum: C++
    Replies:
    3
    Views:
    1,822
    John Harrison
    Apr 22, 2004
  2. rzed
    Replies:
    2
    Views:
    293
  3. Will McGugan

    iter(callable, sentinel)

    Will McGugan, Jul 27, 2006, in forum: Python
    Replies:
    3
    Views:
    459
    Simon Forman
    Jul 27, 2006
  4. Ben Finney

    Sentinel values for special cases

    Ben Finney, Oct 27, 2006, in forum: Python
    Replies:
    7
    Views:
    346
    Gabriel Genellina
    Oct 28, 2006
  5. Mike

    Adding a Sentinel

    Mike, Oct 31, 2004, in forum: C Programming
    Replies:
    3
    Views:
    446
    -berlin.de
    Nov 1, 2004
Loading...

Share This Page