A language construct I’d like to see
A new keyword: once
This would be used in cases where you want to do something once, but not subsequent times the block is encountered. It could be for any language; I'm thinking C# at the moment.
I run across this all the time:
bool bPrintedHeader = false;
while (getSomeData())
{
if (!bPrintedHeader)
{
bPrintedHeader = true;
printHeader();
}
printData();
}
With once:
while (getSomeData())
{
once
{
printHeader();
}
printData();
}
Less code, easier to read, one less variable in scope outside the while. What's not to like?