you still have not understood the concept of the switch statement. there obviously is a difference when you change the order. okay, here another example that will show how a switch can be rewritten using the goto command (which should not be used)...
switch statement code:
int iMissingClothing = CurrentlyMissingClothing(); // 1 - boxer shorts missing, 2 - pants missing, 3 - shirt missing, 4 - hat missing
switch(iMissingClothing)
{
case 1:
SlipIntoBoxerShorts();
// no break here because if we miss the shorts we miss the pants!
case 2:
SlipIntoPants();
break;
case 3:
SlideOnShirt();
break; // again, this is not really needed
} // closing the switch statement execution block here
transcribed code:
int iMissingClothing = CurrentlyMissingClothing(); // 1 - boxer shorts missing, 2 - pants missing, 3 - shirt missing, 4 - hat missing
if(iMissingClothing == 1) goto c1;
else if (iMissingClothing == 2) goto c2;
else if (iMissingClothing == 3) goto c3;
else goto end;
c1: SlipIntoBoxerShorts();
c2: SlipIntoPants();
goto end; // this represents the break
c3: SlideOnShirt();
end: return; // this represents } closing the switch statments execution block
it is apparent that we do not need an extra "goto end;" after finishing c3. also, since the else makes us directly go to "end: return" which represents the end of the switch execution block it is apparent that we do not need a c4 and cDefault that trigger a "goto end;". this is all most basic C++!
as for my second example from above, it may be trivial - i made both of them this way so you'd understand... my bad, assuming you would, here... O_O - but it's not making anything harder to read, in fact it simplifies a whole lot. if you'd make a break; statement after the execution of case 1: you'd have to add the instructions from case 2, to case 1 as well. now, it might not be as bad in my example but imagine you got 30 or 50 lines of complex code there you add twice just because you are desperately trying to close ANY case statement with a break. code should be short and readable. the one i posted above is readable if you do not lack sufficient knowledge of the C++ language...
you know, i got no problem with teaching people stuff about c++ after i spent learning it for some years now. i made many mistakes when i started and i still do some but there is one thing i never tried and that was prove people with apparently superior knowledge in these matters wrong in basics of the language. no problem with you still learning but you honestly need to accept knowledge that we present you. this is not philosophy, this is computer science and if two people and a world renowned software manufacturer (MS) agree upon the terms of usage of switch, case and break they might all actually tell you what the ISO/IEC 14882:2003 set into stone in 2003.
i would have thought better of a linux sys admin... but probably it requires different skill than basic C++ knowledge...
This post has been edited by Stulle: 19 November 2009 - 09:33 PM
I am an emule-web.de member and fan!
Hate me or people will get suspicious about you! Ever wondered if it's all worth the trouble?
No, there will not be a new version of my mods. No, I do not want your PM. No, I am certain, use the board and quit sending PMs. No, I am not kidding, there will not be a new version of my mods just because of YOU asking for it!