sentinel control loops

M

Mistakenidentity18

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
 
M

Mark McIntyre

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;
}
 
K

Keith Thompson

Mark McIntyre said:
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.)
 
B

Ben Pfaff

Keith Thompson said:
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.
 
K

Keith Thompson

Mark McIntyre said:
One could argue that the verb is "to have doubt" ...

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.
 
K

Kenny McCormack

Keith Thompson said:
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.
 
E

Emmanuel Delahaye

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');
}
 
M

Mark McIntyre

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?
 
B

Ben Pfaff

Mark McIntyre said:
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".
 
K

Keith Thompson

Mark McIntyre said:
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.
 
N

Niklas Norrthon

Mark McIntyre said:
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
 
M

Mark McIntyre

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top