- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
No, it's more like this:
i = 0;
LOOP:
if(i < 10) {
i++;
i++;
goto LOOP;
}
Admin
Modus Operandi screews everything, huh?
I don't see what this fantasy you are describing has to do with anything.
I'm not sure what you are on about. Do you not understand what the code does? That it's in a loop is meaningless. It doesn't change the effect of the code no matter what class String is or whatever it is that you are saying.
It doesn't cost anything either.
Admin
No, it's not the same, although very close:
String[] days = new String[] { "Monday", ... };
Admin
Again it's all hypothetical, but even iteration: what if int operator= or ++ are/is overloded. The whole thing is stupid and of course "bad programming practice", but just to state that "loop is meaningless" -- for sure you could...
Admin
If any of the above were true it would be even worse than what it appears to be. The language is not listed, but if it is Java, none of that could be true. Which reminds me why it's a good thing Java doesn't allow overloaded operators.
Admin
I don't get your meaning. Assuming again that this is Java,
String[] days = new String[] { "Monday", ... };
String[] days = { "Monday", ... };
Are completely equivalent.
Admin
</font>
Well done, Blue! You'll be a sarcastic old row-of-asterisks like me before you know it!
(PS What is going on with this forum software? Indenting isn't working either? Is anyone else finding that the formatting buttons are as useless as *** on a bull at the moment?)
</font>
Admin
Exhibit B has a number of possible reasonable interpretations.
Perhaps a sequence of operations might be generate an execption and some way of knowing where this occurred was needed (the value of i provides such
information).
Perhaps an earlier version of this code contained code that was executed
inside the for loop but before/after the switch statement. Subsequent changes
to the code resulted in these statements being deleted. The maintenance
programmer is likely to take the path of least work and leave the for/switch as-is.
Admin
That entire post was a joke, right?
Admin
Horribly confusing. If your context allows for a FIFO data structure that's efficient enough to meet your needs, then it's much simpler to let the producing function run ahead of the consuming function, as in the following pseudocode:
consumer() {while (1) {
while (structure doesn't contain enough data for me to consume)
producer();
pull some data from the structure;
if (EOF)
break;
do something with the data;
}
}
producer() {
push some data to the structure;
}
This way, the producer can push data in whatever size chunks are convenient for the producer's nature, and the consumer can pull data in whatever size chunks are convenient for the consumer's nature - so long as the structure won't overflow.
In the particular example given, the producer would push up to 255 characters at a time, and the consumer would then pull 1 character at a time until the structure was empty again. Thus, a 255-character circular array would work, and would make reasonably efficient use of memory (257 bytes) and speed.
I suppose there are contexts in which you can't spare 257 bytes, but I would sure hate to have to program for them!
Admin
Then why not insert bits of code like (sorry for my C bias):
switch(0) {
case 0: {
putchar ('\n');
}
}
Pax.
Admin
That beats my 41+ case switch in an Action class ;-)
Admin
I have managed development teams, and I find that lines of code is an excellent metric. Only most managers seem to measure it backwards, and think that the team is being more productive when it's going up, rather than down.
Admin
Is this designed for adaptation in the future? Else why not just
public void Execute256OtherFunctions(){
ProcessInternalFindings();
BuildReferences(8,nRef);
...
CleanAllocations();
}
Or am I missing something here?
Admin
COBOL exorcism? You're inhumane!
Admin
You're missing "an extensible, highly performant way to serially execute a number of functions using an adaptable abstration layer to keep the virtualization data clean from object-oriented code block leakage and maintenence hazards through the use of highly portable lesser-known constucts of many languages." Yes, yes you are.
As opposed to what, the hidden native for-loop instructions secretly built into every Intel chip and available only to paying ICL 8 "Pro Edition" customers? >_> There's no such thing as loops at the machine level, though the
But you and the other guy are still wrong, because there's also no if blocks or anything like that. It'd go something like this:
counter=10
loop:
i++
i++
counter--
JUMP TO loop IF counter != 0
(The last two instructions are sometimes grouped into a single LOOP IF counter != 0, with slightly different semantics.)
It becomes:
00400 MOV EAX,i
00402 MOV ECX,10
00405 INC EAX
00406 INC EAX
00407 DEC ECX
00408 TEST ECX,ECX
0040A JNZ 405
(Testing something against itself returns its value to the next instruction.)
Admin
well, well. isn't this the same person who was responsible for this ?
Admin
C64 does that, but also a a renumber command.
Admin
If I had a compiler that mangled my loops that bad, I'd find its author, smash his computer to bits, then get a new compiler.
I'd expect something more like
mov eax, 0
for: inc eax
inc eax
cmp eax, 10
jl for
The greatest amount of compiler psychic ability I could possibly accept is "add eax, 2" instead of two "inc eax". And even that would probably be a Bad Thing(tm).
Admin
Umm, I don't think so. It should be:
loop:
i++
i++
JUMP TO loop IF i < 10
Interestingly enough, for loops, the old Borland compilers (BC++ IIRC, been a while!) used to generate x86 of the form:
<INIT variables>
JUMP TO test
loop:
i++
i++
test:
JUMP TO loop IF i < 10
Presumably, this was to simplify the code generation. When in non-optimising mode, VS.Net 2003 C++ still does something similar. The following code:
for(i = 0; i < 10; i++) {
i++
}
generates:
; for(i = 0; i < 10; i++) {
mov dword ptr [i], 0
jmp test
loop:
mov eax, dword ptr [i]
add eax, 1
mov dword ptr [i], eax
test:
cmp dword ptr [i], 10
jge loop_end
; i++;
mov eax, dword ptr [i]
add eax, 1
mov dword ptr [i], eax
; }
jmp loop
loop_end:
Of course, when compiled with optimisations on (max speed in my test), the compiler simply removes the loop as it doesn't do anything :). If you change it to have another line of j = i * 2;, the compiler generates:
; NB: ecx is used to hold j
; for(i = 0; i < 10; i++) {
xor eax, eax
; i++;
loop:
add eax, 2
; j = i * 2;
mov ecx, eax
add eax, 2
cmp eax, 14h
jl loop
The thing to note is how the compiler recognises that the add and check can be changed to 2 and 20 resepctively, and the use of registers. All part of the magic of optimisation :) (And I can remember the days when a cycle sheet was practically mandatory :), though that was my own code back on the 68000 :))
Admin
Sorry, that should have been:
i = -1
JUMP TO test
loop:
i++
test:
i++
JUMP TO loop IF i < 10
It's *really* been a while! (You get the general idea anyway :))
Admin
Oh dear, better not turn your optimiser on.
I just used that loop, with a following use of the loop counter in a function call, and the entire code resolved to a 'push 10' instruction.
Admin
<FONT face=Arial size=2>Call me crazy but for the first one if it is C# and is for the UI wouldn't you want to do something more like:</FONT>
<FONT size=2><FONT face="Courier New">String[] days = </FONT><FONT face="Courier New" color=#0000ff>new</FONT></FONT><FONT face="Courier New" size=2> String[7];
</FONT><FONT face="Courier New" size=2>System.Globalization.DateTimeFormatInfo culture =
Thread.CurrentThread.CurrentCultureUI.DateTimeFormat;
</FONT><FONT color=#008000><FONT face="Courier New" size=2>// As Sunday is 0 and Monday is 1
</FONT></FONT><FONT size=2><FONT color=#008000><FONT face="Courier New">// But coder wants it to be Monday=0, etc. Sunday=6
</FONT></FONT><FONT face="Courier New" color=#0000ff>for</FONT></FONT><FONT face="Courier New" size=2> (DayOfWeek day = DayOfWeek.Monday; day <= DayOfWeek.Saturday; day++)
</FONT><FONT face="Courier New" size=2>{
</FONT><FONT face="Courier New" size=2>days[day - 1] = culture.GetDayName(day);
</FONT><FONT face="Courier New" size=2>}
</FONT><FONT size=2><FONT color=#008000><FONT face="Courier New">// As Sunday is 0 and coder wants it to be 6
</FONT></FONT><FONT face="Courier New">days[ 6 ] = culture(DayOfWeek.Sunday);</FONT></FONT>
<FONT face="Courier New" size=2>The second example makes my mind boggle... [:|]</FONT>
<FONT size=2><FONT face="Courier New"><FONT style="BACKGROUND-COLOR: #ffffff"><FONT color=#0000ff>case </FONT></FONT>1:
<FONT color=#0000ff>break</FONT>;
<FONT color=#0000ff>case </FONT>2:
BuildReferences(8,nRef);
<FONT color=#0000ff>break</FONT>;
<FONT face=Arial>The <FONT face="Courier New"><FONT face=Arial>"</FONT><FONT face="Courier New">case 1:break</FONT></FONT><FONT face=Arial>" </FONT>is probablly to stop fall through, but why it isn't deleted in it entirity I guess we'll never know...</FONT></FONT></FONT>
<FONT size=2><FONT face="Courier New"><FONT face=Arial>But as V. says why they didn't just write:</FONT></FONT></FONT>
<FONT size=2><FONT face="Courier New">ProcessInternalFindings();
BuildReferences(8,nRef);
</FONT></FONT><FONT size=2><FONT face="Courier New"><FONT color=#008000>//ED: Snip 2-254
</FONT>CleanAllocations();</FONT></FONT>
<FONT size=2><FONT face="Courier New"><FONT face=Arial>Completely escapes me... [:O]</FONT>
</FONT></FONT>Admin
Umm... the forum editor's quite cool with colour and formatting and everything, but doesn't seem to work so well...
Admin
With a smaller font...
Call me crazy but for the first one if it is C# and is for the UI wouldn't you want to do something more like:
<FONT face="Courier New" size=2>String[] days = new String[7];
System.Globalization.DateTimeFormatInfo culture =
Thread.CurrentThread.CurrentCultureUI.DateTimeFormat;
// As Sunday is 0 and Monday is 1
// But coder wants it to be Monday=0, etc. Sunday=6
for (DayOfWeek day = DayOfWeek.Monday; day <= DayOfWeek.Saturday; day++)
{
days[day - 1] = culture.GetDayName(day);
}
// As Sunday is 0 and coder wants it to be 6
days[ 6 ] = culture(DayOfWeek.Sunday);</FONT>
The second example makes my mind boggle...
<FONT face="Courier New" size=2>case 1:
break;
case 2:
BuildReferences(8,nRef);
break;</FONT>
The "case 1:break" is probablly to stop fall through, but why it isn't deleted in it entirity I guess we'll never know...
But as V. says why they didn't just write:
<FONT face="Courier New" size=2>ProcessInternalFindings();
BuildReferences(8,nRef);
//ED: Snip 2-254
CleanAllocations();</FONT>
Completely escapes me...
Admin
I should probably submit this as a WTF, but I don't have the exact code anymore:
bool b = whatever;
...
switch (b) {
case true: DoSomething();
case false: DoSomethingElse();
default: assert(0);
}
Admin
Igor, I understand your point--we do all write stupid code. However, I think you might misunderstand the spirit in which a forum like this is conducted. In certain pursuits there is a tradition of learning from the kind of public roasting that's going on here. What is understood but not said is that most of us would be equally willing to laugh at our own embarrassing mistakes. Indeed, since I've been reading WTF, I've been making mental notes about the vast collection of potential submissions I could cull from my own work.
So maybe lighten up, relax and enjoy the show. No, it doesn't pay any bills, but if you can't spare the time from bringing home the benjamins, that's ok too. I really don't have time to burn here either, but I do anyway--everybody has to have a hobby... haha.
Admin
This is the second time in a week that I've read about Duff's Device. I /still/ don't "get it" -- how does it work? what the hell does it DO?
update: while typing this, I went back and re-read the page, and now I think I get it. ::embarassed:: But, I'm not sure... anyone want to do an explanation of When You've Found It Useful? (and why)
=D
Admin
What "escapes" you is the possibility that "i" maybe changing inside Snip 2-254...
I'm not insisting that it is changing. And I'm not defending that ugly code, but the possibilty of "i" changing is very strong...
Admin
I still dont see whats wrong with any of this code!!
Admin
Jeff, "That entire post was a joke, right?":
Why are you saying that? What's wrong with my post?
Admin
"well, well. isn't this the same person who was responsible for this ?"
Yes, that's me: so what? At least it works: what have you write recently?
Admin
If you are not joking, step away from the computer.
Admin
What exactly are you responsible for? The ad?
Admin
It used to be very common, actually, especially in COBOL shops. Even in cases where it is not a formal policy, you still run into plenty of managers who see raw code output as a measure of productivity, even when the code is inefficient or even non-functional.
Corpse-rat politics often encourages such wasteful practices. Larger projects, with more people and more lines of code, are more prestigious, so empire-building middle managers often pad projects at the expense of actually completing them. Since middle managers (in any company large enough to have them) are largely insulated from criticism - the blame for failure usually falls on either the upper management or on the rank and file - this can become a corporate cancer which is very difficult to eliminate once it has taken hold.
Admin
dubwai , you for sure have a lot of extra available time to be involved with useless participation in weird discussions.
The question is: what you gain from that? OK: we establsihed the code above is bad! So, go on with your life: Trust me: the life is too short --I know -- this is my second life -- previous one I lived in India and worked for outsourced software company...
Admin
Apparently you also have the time. It doesn't take long to post a comment though. Do it while I'm waiting on processing.
What do you gain from posting these replies?
I don't know what that has to do with anything but if you think this is such a waste of time, why are you posting here?
Admin
Scoff all you want, but a switch statement inside a for loop can be very useful. For instance, in the current project at work, there's a custom grid control, with the columns and their names predefined in stdafx (it makes it much easier to move a column due to a client's demands). Now when building the grid, columns turn on and off depending on the analysis run. So... there is a for loop that loops through all the column indices, with a switch loop inside for (almost) every column name. Since certain columns are grouped with certain analyses, you can turn a bunch on an off at once. The default switch is used for columns that are always enabled. It's much easier to read this way and easier to move columns around in case something changes, things need to be removed, things need to be added, etc. A laundry list of if/else statements going on for all nTotalCols would be IMHO worse code. On top of that, switch statements are faster than if/else combinations.
Example:
for(nCol = 0; nCol<nTotalCols; nCol++)
{
{
Col_Bart:
Col_Homer:
Col_Lisa:
Col_Marge:
Col_Maggie:
//snip
default:
And here's an example for text input from this C# program I'm working on. Given, The order of commands in the text file is usually going to be PowerWord->Action->Purpose->Names. But what if somebody decides to change their mind in the future and swaps Purpose with Names in the text file? What if some moron put in a bunch of blank lines between [/PowerWord] and [Action]? It's one less function to change/debug.
while ((strRead = fileInput.ReadLine()) != "[EndOfFile]")
{
switch(strRead)
{
case "[PowerWord]":
while ((strRead = fileInput.ReadLine()) != "[/PowerWord]")
{
listPowerWord.Items.Add(strRead);
}
break;
case "[Action]":
while ((strRead = fileInput.ReadLine()) != "[/Action]")
{
listAction.Items.Add(strRead);
}
break;
case "[Purpose]":
while ((strRead = fileInput.ReadLine()) != "[/Purpose]")
{
listPurpose.Items.Add(strRead);
}
break;
case "[Names]":
while ((strRead = fileInput.ReadLine()) != "[/Names]")
{
comboIdentity.Items.Add(strRead);
}
break;
default:
break;
}
}
So: in the big picture of things, is this slower? not by much since a switch statement is pretty fast, and much faster thant if/elseif/else combinations (that would have been worse than a switch inside a for loop). Is this code easier to maintain, change, more bug proof, and easier to debug? YES! Should it be used to replace a simple list of assignments, where EVERY single item in the list gets unique code (like the days of the week)? OF COURSE NOT!
For the examples given, yes, WTF definitely on days of the week. A smarter idea would have even to put that in a predefined string table. But there ARE situations where this is useful.
Admin
To pre-empt any nit-picking, the forum ate half the first line and last bracket of my for loop :)
Admin
I doubt that using a switch with Strings is going to be any faster than linked ifs. Switch can be faster with int types because the compiler can build a jump table for the values. It's more complicated with sparse values but for consecutive values the compiler can basically jump n instructions (over-simplification) when the input to the switch is n. You can't really do that with Strings. This is why Java doesn't allow switch with anything but int types. I'm going to guess that C# just allows this as syntactic sugar.
In any event the speed increase (if there is any) if likely to be negligible. If it makes the code clearer, that's good but I hate when people obfuscate code in the name of (imaginary) 'optimization'.
Admin
Being new to C#, I was shocked when it allowed strings, and I agree, whatever was gained switching with int is probably lost when using strings (not knowing the exactly what the compiler does, we can't be sure though!). However, I don't think using switch obfuscates code at all. if/elseif/else tends to make my eyes hurt. I guess this is one of those "personal preference" things. One of my coworkers for example prefers if/elseif/else over switches. Whatever floats your boat I guess?
On a side note, I've started using the ? : statement for certain if clauses after I discovered it recently. I can definitely understand how that statement could probably drive people up the wall if used obsessively :D
Admin
Unless you've got a method for creating jump tables based on Strings, I'm going stick with syntactic sugar. I just don't think it's feasible.
I wasn't suggesting that using switch was obfuscation. I was clarifying that just because there was no optimization doesn't mean there was no value in using switch for Strings. In other words it's generally better to make code easy to understand than try to squeeze every last bit of performance out if it.
I really like unary if as long as it isn't abused.
Admin
Speaking of which, I just found my first WTF looking through some code today, so I decided to submit it. It just happens to be a unary if abuse:
Notice the last parameter.
Admin
Admin
<FONT size=4>
</FONT>Admin
igor: The entire reason for this forum is to make fun of bad programmers. If you don't like it, don't visit the site. It's really that simple.
Admin
I can't speak for the designers, but two reasons stand out: Consistency (maybe even a coding standard - that could be the real wtf!), and a default: that actually does something, but since it's not at either end I'd have to assume it's in the middle if it was there. Most likely it was at the end and new values accreted onto the end of it! xD I've seen that, and it's a huge wtf for maintainers.
Since this is C++ it's equivalent to (bool)bUseMask or if the function is defined as bool, bUseMask alone. It might be a C compatible function even though it's in a class/namespace, though. It's just a silly way of writing it.
C# does just that, as well as modern java compilers/runtime jitters. It replaces the string constants in preprocessing with int indexes to the strings. So do other non-VB6 languages that handle strings in switches, like PHP and Perl. And while comparing your string against them to come up with the int is still hard, some compilers add a small index to speed the process considerably; I think VC 2005 does that, and maybe 2003.
There was a second variable that was being incremented with the counter.
The pipeliner would decompile add eax,2 into two inc eax anyway, and both take as long to be pushed into the processor, so it makes no difference. (Except in shared-memory multithreading.) But if that alone is a Bad Thing, then I guess you haven't used release/optimize modes in any compiler since 1990. I'd hate to see your executables.
I know, too long. Should have double-posted. Oh well. =p Igor's hilarious, too, like a nosy old neighbor.
Admin
<FONT face="Courier New" size=2><FONT color=#0000ff>using</FONT> System;
<FONT color=#0000ff>using</FONT> System.Collections;
<FONT color=#0000ff>using</FONT> System.Text;
<FONT color=#0000ff>namespace</FONT> MoneyString
{
<FONT color=#008000>///
<FONT color=#0000ff>public</FONT> <FONT color=#0000ff>class</FONT> Money
{
#<FONT color=#0000ff>region</FONT> Enumerations
<FONT color=#0000ff>enum</FONT> MoneyPower
{
Hundred = 1,
Thousand = 2,
Million = 3,
Billion = 4,
Trillion = 5
}
<FONT color=#0000ff>enum</FONT> Ones
{
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9
}
<FONT color=#0000ff>enum</FONT> Tens
{
Ten = 1,
Twenty = 2,
Thirty = 3,
Forty = 4,
Fifty = 5,
Sixty = 6,
Seventy = 7,
Eighty = 8,
Ninenty = 9
}
<FONT color=#0000ff>enum</FONT> TensSpecial
{
Eleven = 1,
Twelve = 2,
Thirteen = 3,
Fourteen = 4,
Fithteen = 5,
Sixteen = 6,
Seventeen = 7,
Eightteen = 8,
Nineteen = 9
}
#<FONT color=#0000ff>endregion</FONT>
#<FONT color=#0000ff>region</FONT> Methods
<FONT color=#008000> ///
/// Transforms a number into an English(Word) Readable Money Value.
///
/// <PARAM name="money">A number.</PARAM>
/// <RETURNS>English Word Money String.</RETURNS></FONT>
<FONT color=#0000ff>public</FONT> <FONT color=#0000ff>static</FONT> <FONT color=#0000ff>string</FONT> ToString(<FONT color=#0000ff>int</FONT> money)
{
#<FONT color=#0000ff>region</FONT> var
StringBuilder sb = new StringBuilder();
<FONT color=#0000ff>string</FONT>[] mon = money.ToString("C").Split(',');
<FONT color=#0000ff>string</FONT> ret = "Ammount can not exceed $999,999,999,999,999.00";
<FONT color=#0000ff>string</FONT> sCache = "";
<FONT color=#0000ff>int</FONT> iCache = 0;
<FONT color=#0000ff>bool</FONT> skip = false;
#<FONT color=#0000ff>endregion</FONT>
#<FONT color=#0000ff>region</FONT> Return if Number is to Large
<FONT color=#0000ff>if</FONT>(mon.Length > 5) <FONT color=#0000ff>return</FONT> ret; <FONT color=#008000>//more than 5 is alot of money</FONT>
#<FONT color=#0000ff>endregion</FONT>
#<FONT color=#0000ff>region</FONT> clean string
mon[0] = mon[0].Replace("$",""); //remove dollar sign
mon[mon.Length - 1] = mon[mon.Length - 1].Split('.')[0]; <FONT color=#008000>//trim of the decimal places</FONT>
#<FONT color=#0000ff>endregion</FONT>
#<FONT color=#0000ff>region</FONT> Loopy Money Switch
<FONT color=#0000ff>for</FONT>(<FONT color=#0000ff>int</FONT> i = 0; i < mon.Length; i++)
{
<FONT color=#0000ff>for</FONT>(<FONT color=#0000ff>int</FONT> j = 0; j < mon[i].Length; j++)
{
<FONT color=#0000ff>switch</FONT>(mon[i].Length)
{
<FONT color=#0000ff>case</FONT> 1:
#<FONT color=#0000ff>region</FONT> Ones
sCache = mon[i].Substring(j, 1);
iCache = int.Parse(sCache);
<FONT color=#0000ff>if</FONT>(iCache > 0)
{
sCache = ((Ones)iCache).ToString();
sb.Append(sCache);
}
sb.Append(" ");
<FONT color=#0000ff>break</FONT>;
#endregion
<FONT color=#0000ff>case</FONT> 2:
#<FONT color=#0000ff>region</FONT> Place Switch
<FONT color=#0000ff>switch</FONT>(j)
{
<FONT color=#0000ff>case</FONT> 0:
#<FONT color=#0000ff>region</FONT> Tens
sCache = mon[i].Substring(j, 1);
iCache = int.Parse(sCache);
<FONT color=#0000ff>if</FONT>(iCache > 0)
{
<FONT color=#0000ff>if</FONT>(iCache == 1)
{
sCache = mon[i].Substring(j + 1, 1);
iCache = int.Parse(sCache);
sCache = ((TensSpecial)iCache).ToString();
sb.Append(sCache);
skip = <FONT color=#0000ff>true</FONT>;
}
<FONT color=#0000ff>else</FONT>
{
sCache = ((Tens)iCache).ToString();
sb.Append(sCache);
}
}
sb.Append(" ");
<FONT color=#0000ff>break</FONT>;
#<FONT color=#0000ff>endregion</FONT>
<FONT color=#0000ff>case</FONT> 1:
#<FONT color=#0000ff>region</FONT> Ones
<FONT color=#0000ff>if</FONT>(!skip)
{
sCache = mon[i].Substring(j, 1);
iCache = int.Parse(sCache);
<FONT color=#0000ff>if</FONT>(iCache > 0)
{
sCache = ((Ones)iCache).ToString();
sb.Append(sCache);
}
sb.Append(" ");
}
skip = <FONT color=#0000ff>false</FONT>;
break;
#<FONT color=#0000ff>endregion</FONT>
}
#<FONT color=#0000ff>endregion</FONT>
break;
<FONT color=#0000ff>case</FONT> 3:
#<FONT color=#0000ff>region</FONT> Place Swich
<FONT color=#0000ff>switch</FONT>(j)
{
<FONT color=#0000ff>case</FONT> 0:
#<FONT color=#0000ff>region</FONT> Hundreds
sCache = mon[i].Substring(j, 1);
iCache = int.Parse(sCache);
<FONT color=#0000ff>if</FONT>(iCache > 0)
{
sCache = ((Ones)iCache).ToString();
sb.Append(sCache);
sb.Append(" ");
}
sb.Append(" ");
<FONT color=#0000ff>break</FONT>;
#endregion
<FONT color=#0000ff>case</FONT> 1:
#<FONT color=#0000ff>region</FONT> Tens
sCache = mon[i].Substring(j, 1);
iCache = int.Parse(sCache);
<FONT color=#0000ff>if</FONT>(iCache > 0)
{
<FONT color=#0000ff>if</FONT>(iCache == 1)
{
sCache = mon[i].Substring(j + 1, 1);
iCache = int.Parse(sCache);
sCache = ((TensSpecial)iCache).ToString();
sb.Append(sCache);
skip = <FONT color=#0000ff>true</FONT>;
}
<FONT color=#0000ff>else</FONT>
{
sCache = ((Tens)iCache).ToString();
sb.Append(sCache);
skip = <FONT color=#0000ff>false</FONT>;
}
}
sb.Append(" ");
<FONT color=#0000ff>break</FONT>;
#endregion
<FONT color=#0000ff>case</FONT> 2:
#<FONT color=#0000ff>region</FONT> Ones
sCache = mon[i].Substring(j, 1);
iCache = int.Parse(sCache);
<FONT color=#0000ff>if</FONT>(iCache > 0)
{
<FONT color=#0000ff>if</FONT>(!skip)
{
<FONT color=#0000ff>if</FONT>(mon[i].Substring(1, 1) != "0")
{
sb.Remove(sb.Length - 1, 1);
sb.Append("-");
}
sCache = ((Ones)iCache).ToString();
sb.Append(sCache);
}
}
skip = <FONT color=#0000ff>false</FONT>;
sb.Append(" ");
<FONT color=#0000ff>break</FONT>;
#<FONT color=#0000ff>endregion</FONT>
}
#<FONT color=#0000ff>endregion</FONT>
<FONT color=#0000ff>break</FONT>;
}
#<FONT color=#0000ff>region</FONT> Add Hundred..?
<FONT color=#0000ff>if</FONT>(mon[i].Length == 3 && j == 0 && mon[i].Substring(j, 1) != "0")
{
sb.Append("Hundred");
sb.Append(" ");
}
#<FONT color=#0000ff>endregion</FONT>
}
#<FONT color=#0000ff>region</FONT> Add Power..?
<FONT color=#0000ff>if</FONT>(i != (mon.Length - 1))
{
sCache = ((MoneyPower)mon.Length - i).ToString();
sb.Append(sCache);
sb.Append(" ");
}
#<FONT color=#0000ff>endregion</FONT>
}
#<FONT color=#0000ff>endregion</FONT>
#<FONT color=#0000ff>region</FONT> Get, Append Dollars, and Return English Money String
ret = sb.ToString();
ret += "Dollars";
<FONT color=#0000ff>return</FONT> ret;
#<FONT color=#0000ff>endregion</FONT>
}
#<FONT color=#0000ff>endregion</FONT>
}
}</FONT>
I had wanted to say something, but now after having to <FONT color=#ff0000 size=6>HTML FORMAT MY CODE I FORGOT, WTF</FONT>. Can we like turn the lame @$$ WYSIG HTML Editor Spoof off so I can use my BBCode tags...? You know
[php]WTF[/php][vbcode]WTF[/vbcode]:cool: I mean if we are posting code let's make it easy not hard... wtf am I just stupid..? I mean the other forums I use let me turn that funk off....... I can pick like plain text, lite editor, and full wysig htm crap iframe document.open(iframe.document).write('wtf');Admin
Um, quick question. Why didn't you just use string.Format("$%.2f", dSomeFloatingPointUSDollars), since it looks like you're using C#?
Admin
Java doesn't allow switching on Strings so I'm not sure what you mean when you say Java compilers do this. There are going to be more Strings than integer values in most languages. I still don't see how you can create a jump table. If you are talking about a hashtable, well, that's something else entirely.