while(...){ ... }else ...
MattCoder via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jan 18 15:27:38 PST 2015
On Sunday, 18 January 2015 at 22:54:16 UTC, Jens Bauer wrote:
> On Sunday, 18 January 2015 at 16:03:24 UTC, MattCoder wrote:
>> On Sunday, 18 January 2015 at 15:52:24 UTC, Jens Bauer wrote:
> ...
> First check: Is it a number; if so, get the entire number... If
> not, try the second check: is it a token; if so, get the entire
> token, otherwise let us know that it's something unknown (but
> only if we're debugging).
Alright I see the purpose about: "while(){}else(){}", but
unfortunately D doesn't have this.
Anyway looking at your first post, I'd like to suggest a way to
improve your code:
/*
Create a "type check" function/method... you named it returning a
defined type */
import std.string;
type checkType(sometype s){
if(isNumeric(s)){
return TYPE_NUMBER;
}
// Check using regex for A..Z, a..z and '_'
return TYPE_TOKEN;
return TYPE_UNDEFINED;
}
// And then somewhere in your code you could do this:
...
{
switch(checkType(s)){
case TYPE_NUMBER : doNumberThing(s); break;
case TYPE_TOKEN : doTokenThing(s); break;
default : checkDebug();
}
}
It's not what you proposed earlier, but I think it can make
things easier.
Matheus.
More information about the Digitalmars-d
mailing list