Aaa.... I think you meant it this way: PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer Dim a as Integer Dim b as Integer
REPEAT IF TabStrip3[a].Caption = IdCaption THEN b = TabStrip3.Count BREAK ENDIF WHILE a < TabStrip3.Count RETURN b END Jussi On Wed, Apr 14, 2010 at 01:55, Jussi Lahtinen <jussi.lahti...@gmail.com> wrote: > First you referred to FOR loop only, > but with case of return command you are talking more generally about loops? > Or so I understand as you are speaking about it's influence to code structure. > > Consider this, if you have VERY long iteration and but you are done > with first element of iteration. > Then there is no reason to continue iteration anymore, because it is > just waste of time. > > Let's take your example (I did clean it up): > > PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer > Dim a as Integer > > FOR a = 0 TO TabStrip3.Count - 1 > IF TabStrip3[a].Caption = IdCaption THEN > RETURN TabStrip3.Count > ENDIF > NEXT > > RETURN 0 > END > > Now this is not very realistic case with this example, but let's > pretend it is so. > Let's say that this iteration takes 10 second to run trough and there > are 10 items. > When first item is what is needed, then this function takes only 1 > second to execute. > If we do not break that loop it will always take 10 seconds. > > Just to make sure, you meant it should be like this? > > PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer > Dim a as Integer > Dim b as Integer > > FOR a = 0 TO TabStrip3.Count - 1 > IF TabStrip3[a].Caption = IdCaption THEN > b = TabStrip3.Count > ENDIF > NEXT > > RETURN b > END > > > Also you should notice, that this is normal practice in Basic languages. > And therefore also question of portability. > > Jussi > > > > 2010/4/14 Fabián Flores Vadell <fabianfloresvad...@gmail.com>: >>> Why shouldn't the compiler allow to modify a loop variable? It is sometimes >>> useful. >> >> I'm refering to the loop FOR only. IMHO, WHILE and REPEAT are good >> structures that allow at programmer take absolute control over >> iterations, objective of FOR is iterate all items of a memory >> structure. At least, I think that was of the original design purpose >> (distorted after). >> >> In fact, the need of FOR structure is relative. Any need can be easily >> cover with WHILE and REPEAT. >> >> I don't see the need for break a iteration structure from inside, in >> any way (even break and continue). This would be done from conditional >> input or output of the structure. But I see the consecuences. >> >> May be, the exeption to this is FOR EACH structure. >> >>> Why shouldn't the compiler allow to return from inside a loop? It is >>> perfectly >>> valid to do that. >> >> Why allow break a loop in this way? That often leads to write multiple >> statements RETURN in a function. That does not comply with the >> theorem of structured programming (that have as one of its premises >> allow only a input point and unique exit). I think that in practice >> this difficults the tests; if necesary to port the code, this could be >> an aditional problem; among other things. >> >>> A bad programmer using some syntax for writing bad code does not necessary >>> imply that that syntax should be forbidden. >> >> I agree, but actually I was thinking that this affect more to those >> who approach programming in an informal way. >> >> >> -- >> Fabián Flores Vadell >> www.speedbooksargentina.blogspot.com >> >> ------------------------------------------------------------------------------ >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev >> _______________________________________________ >> Gambas-user mailing list >> Gambas-user@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/gambas-user >> > ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user