The While If
-
Here's one you've probably seen before..
while ( GlobalBufferPos > BytesToRead )
{
if (//enough space)
{
//copy data to GlobalBuffer
}
else
{
Temp = //space left;
// copy data into GlobalBuffer
// copy data into GlobalBuffer2
}
GlobalReadPos += BytesToRead;
if(GlobalReadPos > MAX_SIZE) GlobalReadPos -= MAX_SIZE;GlobalBufferPos -= BytesToRead; WriteData(...); Temp = BytesToRead break;
}
// return ... ;I suppose it made sense at the time.
-
Here's one you've probably seen before..
while ( GlobalBufferPos > BytesToRead )
{
if (//enough space)
{
//copy data to GlobalBuffer
}
else
{
Temp = //space left;
// copy data into GlobalBuffer
// copy data into GlobalBuffer2
}
GlobalReadPos += BytesToRead;
if(GlobalReadPos > MAX_SIZE) GlobalReadPos -= MAX_SIZE;GlobalBufferPos -= BytesToRead; WriteData(...); Temp = BytesToRead break;
}
// return ... ;I suppose it made sense at the time.
Yeah, probably. I would assume that originally they wanted the
while
and later decided otherwise; I would either have removed thewhile
or made thebreak
conditional. -
Here's one you've probably seen before..
while ( GlobalBufferPos > BytesToRead )
{
if (//enough space)
{
//copy data to GlobalBuffer
}
else
{
Temp = //space left;
// copy data into GlobalBuffer
// copy data into GlobalBuffer2
}
GlobalReadPos += BytesToRead;
if(GlobalReadPos > MAX_SIZE) GlobalReadPos -= MAX_SIZE;GlobalBufferPos -= BytesToRead; WriteData(...); Temp = BytesToRead break;
}
// return ... ;I suppose it made sense at the time.
I have on occasion used:
{
...
do {
...
if (condition) break;
...
if (condition) break;
...
} while(0);
...with the while() "loop" being merely a block from which the code could "break". I wonder if the code here began as something similar, but replacing an "if()" and "do {} while()" with a "while()" and a "break".
-
I have on occasion used:
{
...
do {
...
if (condition) break;
...
if (condition) break;
...
} while(0);
...with the while() "loop" being merely a block from which the code could "break". I wonder if the code here began as something similar, but replacing an "if()" and "do {} while()" with a "while()" and a "break".
No, that horror is by people who think it's less of a horror than a
goto
. -
No, that horror is by people who think it's less of a horror than a
goto
.PIEBALDconsult wrote:
No, that horror is by people who think it's less of a horror than a goto.
Many modern languages support exceptions on the basis that conventional structured programming constructs can't practically handle everything that programs need to do. In languages which support exceptions, they should be used when appropriate. What would you suggest doing, if not a 'goto' or 'break', in situations where an exception would be appropriate but the language doesn't support them? BTW, I wish some standards agency would draft an extension of the C99 standard which would allow something like exceptions but only within a particular function (C++, which allows full-fledged extensions, already exists, but run-time support for exceptions requires too much overhead to be practical on some smaller microcontrollers; limited support for exceptions within a function could improve program structure without impacting code size, speed, or RAM requirements.
-
PIEBALDconsult wrote:
No, that horror is by people who think it's less of a horror than a goto.
Many modern languages support exceptions on the basis that conventional structured programming constructs can't practically handle everything that programs need to do. In languages which support exceptions, they should be used when appropriate. What would you suggest doing, if not a 'goto' or 'break', in situations where an exception would be appropriate but the language doesn't support them? BTW, I wish some standards agency would draft an extension of the C99 standard which would allow something like exceptions but only within a particular function (C++, which allows full-fledged extensions, already exists, but run-time support for exceptions requires too much overhead to be practical on some smaller microcontrollers; limited support for exceptions within a function could improve program structure without impacting code size, speed, or RAM requirements.
Huh? I use
goto
when necessary (which is very rare). -
Huh? I use
goto
when necessary (which is very rare).goto
bathroom.goto
kitchen.goto
pub. They seem necessary :-D
Panic, Chaos, Destruction. My work here is done.
-
goto
bathroom.goto
kitchen.goto
pub. They seem necessary :-D
Panic, Chaos, Destruction. My work here is done.
Only the bathroom is a necessary.
-
Only the bathroom is a necessary.
Just an optional requirement..... :laugh: