goto loops
-
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
Lucian-aSterX wrote:
i just saw that a collegue uses
How old is your colleague? When I first learned to program, a "GOTO/JUMP" was the only way to break a loop before completion or to branch (i.e. early Fortran, original BASIC & 6502 assembly, etc). And I still tend to think in DO/FOR loops and GOTO line number. But I try to avoid using line numbers these days. We didn't have these modern languages like C and still used punched cards and paper tape (I am must be seriously old!).
Melting Away www.deals-house.com www.innovative--concepts.com
-
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
-
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
It seems to me, the GOTO statement goes back to the original Basic Programming of the early seventies, where it had really valid uses. Because resources, especially memory, was so scarce, you used less precious bytes when you used a GOTO instead of a FOR loop. Nowadays, it's more used for getting out of some sticky situations such as multiple nested loops or to get around such things. It's much more elegant and sound to set a boolean flag and just check it at every step out of the structure. What do you guys think?
-
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
I just got through reading all the comments (as of the time I'm posting). Here's my 2 cents. I skipped formal religious training (ie degree in computer science from university -- taught by monks who are constrained to teach the latest C.S. fad or risk losing their jobs) and instead "squandered" my time at university studying math and science (my parents were so ashamed :(( ). Anyway, because of my secular education, I tend to be mostly agnostic when it comes to religious wars on subjects like: - use of goto - use of macros - procedural versus Object Oriented, versus Aspect Oriented programming - which language (Python, Java, C#, etc.) the angels in heaven speak - which language (Cobol, Fortran, Algol, etc.) the demons in hell speak. I once heard a man say to his deeply religous mother, "But mom, even Jesus drank wine", to which she responded "Yes, but I'd have thought better of Him if He hadn't!" Perhaps there are just times when the angels, in order to be understood by us mere mortals, stoop to vile "hell-speak" and use goto. At which point, we would have thought better of them if they hadn't... ;)
David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------
-
Lucian-aSterX wrote:
i just saw that a collegue uses
How old is your colleague? When I first learned to program, a "GOTO/JUMP" was the only way to break a loop before completion or to branch (i.e. early Fortran, original BASIC & 6502 assembly, etc). And I still tend to think in DO/FOR loops and GOTO line number. But I try to avoid using line numbers these days. We didn't have these modern languages like C and still used punched cards and paper tape (I am must be seriously old!).
Melting Away www.deals-house.com www.innovative--concepts.com
Snowman58 wrote:
How old is your colleague?
My collegue is about ~35 years old... but i don't think tha using goto has a lot to do with age, because i remember when i was in college (~2 years ago) the programming teacher (C#) told us about goto loops and teached us how to use this. I have to admit that he wasn't so good at programming, anyway... this may be the reason...
-
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
-
A break statement in C# is like a GoTo statement in VBA, except that is just takes the code out of the active loop. GoTo statements should be forward moving (in the method) only - else spaghetti code ensues. It's sometimes easier to use a GoTo statement in VBA (e.g., instead of a do while loop), within a standard iterator loop, to exit the loop. But VBA does have an exit do statement. There should be no need to use a GoTo statement in C#.
-
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
I taught myself programming in TI-BASIC on a TI-83+ at school. I'd already learnt area in year 7 (after skipping 3 years :P) so didn't feel the teacher was worth my time. Moved on to Assembly, then C. Then went to uni in an I.T. degree which of course included programming units. And I saw much, much worse than a simple GoTo by the very people that were telling me GoTo is evil and should die. From which the lesson I gathered was, if you know how to use a programming construct, than do so. If you don't, avoid it. That's the rule of coding. Don't just do or not do because you were told by someone that it's good/bad for you as the case may be, that makes you absolutely useless. And I mean that in the nicest possible way of course. ;P
-
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
Generally I do not use gotos in c# but there is one exception with regards to switch (cases) where you want to process multiple cases. For example, I have a data driven website where certain css classes are listed in data and applied to a user control in order. They are all optional but want to process each one specified in a specific way, so I created something like:
char sepChar = '|';
string[] array = dataString.Split(sepChar);switch (array.length)
{
case 3:
dosomeassign(array[2], element5);
goto 2;
case 2:
dosomeotherassign(array[1], element4);
goto 1;
case 1:
dosomeassign(array[0], element2);
break;
}WarePhreak Programmers are tools to convert caffiene to code.