2.) SWITCH functions only with numeric logic, as I now think
is the only way it works. That's what I learned in the
Watcom Forum when this question was posed there.
That works fine for numeric-based stuff. In my limited knowledge of C++, can degenerate into lots and lots of lines of code for non-numeric logic.
still seems to me that handling strings ain't near so easy in C++ as it is BASIC, sigh..
I think Sarah is faced with this same problem as well, but maybe not in WA V11, but some other compiler. Thus the problem is generic? But is sure i OS/2 programming related, at least to me and I suspect others.
Mike,
Yes, it's difficult. But look at it from a different
angle: All char's have a numeric equivalent, and you
don't have to use that numeric equivalent to check
for chars in a switch:
char num[2];
// get a number/char whatever in num[]
switch (*num)
{
case '0':
.
case '9':
case 'a':
case 'A':
case 'b':
case 'B':
.
.
default:
};
I've been discussing Sarah's problem with her via e-
mail, and the solution was similar to the above.
But .. that doesn't help much where the comparator was X$, for example and is a variable length string. I was a bad boy at an earlier time in life a
I'm not much better now. Basicly, I'm still trying to digest what I ate w I was a younger programmer. Gloom.
But .. that doesn't help much where the comparator was X$, for
example and X$ is a variable length string. I was a bad boy
at an earlier time in life and I'm not much better now.
Basicly, I'm still trying to digest what I ate when I was a
younger programmer. Gloom.
...I'm about 60% through writing an auto-translator from
PowerBASIC 3.5 source to Watcom V11 (b). It's been
educational. One of the things that has been a stumbling block
to me is the use of CASE in BASIC where the switch logic is
based not on numeric conditionals, but alpha conditionals...
No, it doesn't help with that much at all. :)
You could do a series of nested switch statements
(check first letter, check
second letter, etc... until you've narrowed it down to
a unique value), but
that could get real hairy.
... even if only to assign a single value to
be able to case or switch with... however, doing that
if/then/else tree once and then using the single value
every else is much better than using if/then/else
everywhere that you need to branch based on that
selection...
If I may ask... do your "alpha conditionals" test for bit patterns?
If so, might you rewrite them using numeric values of those bit
patterns?
Yes, Mark .
... even if only to assign a single value to
be able to case or switch with... however, doing that
if/then/else tree once and then using the single value
every else is much better than using if/then/else
everywhere that you need to branch based on that
selection...
Wincing .. "The devil you know is better than the devil you
don't?"
one of the things i was thinking about while writting the above was 'program efficiency'... in some situations this can be
important...
if switch case is faster then if/then/else, then
'converting' to single value for that purpose once is
a necessary evil until such time as one gets the
chance to rework that section...
thinking about situations where the switch case stuff
may possibly be executed hundreds of times a second vs
if/then/else trees running hundreds of times a
second...
== example ==
red == 1;
blue == 2;
yellow == 3;
procedure routine1;
{
input "what's your color?",color$;
if color$ = "red" then color == red
else if
color$ = "blue" then color == blue
else if
color$ = "yellow" then color == yellow;
}
procedure routine2;
{
case color of
red : do_red_routine;
blue : do_blue_routine;
yellow : do_yellow_routine;
}
procedure routine3;
{
case color of
red : do_red_routine2;
blue : do_blue_routine2;
yellow : do_yellow_routine2;
}
{
routine1;
while 1==1 do
{
routine2;
routine3;
}
}
== end of example ==
But .. that doesn't help much where the comparator was X$, for example and is a variable length string. I was a bad boy at an earlier time in life an I'm not much better now. Basicly, I'm still trying to digest what I ate wh was a younger programmer. Gloom.
Sysop: | digital man |
---|---|
Location: | Riverside County, California |
Users: | 1,023 |
Nodes: | 17 (1 / 16) |
Uptime: | 181:05:08 |
Calls: | 502,435 |
Calls today: | 3 |
Files: | 100,639 |
D/L today: |
218 files (93,603K bytes) |
Messages: | 437,172 |