"Returning" in middle of loop bad practice?

Started by
22 comments, last by paulcoz 23 years, 3 months ago
quote:Original post by Yanroy

If you are going to talk about goto usage (again...), I feel the need to boast. I don''t even KNOW HOW to do a goto! So you will never find them in my code



Well, beat this: Seeing as i''m a self taught programmer, and I started my learning in Borland C++ Builder 3.0 (cough ), I developed some strange habits in my code... I saw ''return'' in other people''s code (I think Carmack''s... not sure what it was I was trying to figure out though) so I thought they were for the l33t h4x0rz, or something. However, I became frustrated by not being able to get out of a function before it finished, so I stumbled across ''goto''. So, every time I wanted to bail out of a function, i''d have a lable defined right at the end of it (called ''End:'' usually ) and where i''d now put ''return'' I put ''goto End;''. Hah. I thought I was the bees-knees.
Those were the days...



Insomnia
Insomnia
Advertisement
quote:
Woah, thanks for the vote of confidence there... guess that throws away any chance I had of being able to write anything non-trivial in assembler, huh?


Blah blah yea i know, but if u noticed, i was speaking of high level languages, not assembly.


BetaShare - Run Your Beta Right!
quote:Original post by LordElectro


Woah, thanks for the vote of confidence there… guess that throws away any chance I had of being able to write anything non-trivial in assembler, huh?


Blah blah yea i know, but if u noticed, i was speaking of high level languages, not assembly.




Either it works or it doesn''t, regardless of what level of language you''re using. It''s all a matter of whether or not you have the discipline not to screw it all up. In fairness, the higher level constructs are good at making the code more self-documenting (in much the same way as ret is a nice way of not having to pop registers and jump yourself).
Assembly language does not preclude the use of structured programming and it is in fact of greater benefit within assembler. It isn''t whether you use gotos or their equivilants, but rather the manner in which control flows through the program. C/C++ programs in all likelyhood will be structured whether the programmer is aware of the rules of structured programming or not. Within assembler it is unlikely to be structured unless the programmer is aware of structured programming and makes a specific effort to write a structured program. It is effectively far more important to use structured programming within assembler than in any other language because if you don''t make the effort it will be far less structured than any other language excluding machine code which is effectively the same thing.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement