none
[SB REQUEST] "For Each" key-word.

    General discussion

  • Hi,

    I found that small basic had something missing, and it was something very useful...

    The "For Each" key word, used in visual basic, and in many others languages, it could be very useful instead of running endless while or for loops without knowing how many times you should run some function.

    Friday, March 16, 2012 12:52 PM

All replies

  • Yeah! That would be swell!! I hope they implement this idea! :)


    Nevin Janzen (Visit my Website)
    If this post answers your question, please click Propose As Answer. If this post is helpful, please click Vote As Helpful.
    How to Get Better Answers to Your Questions

    Monday, April 30, 2012 2:01 AM
  • Hi AskoreDracon,

    Could you provide an example, there could be many ways around not needing this.

    Kirk.


    • Edited by Kirkkaf Monday, April 30, 2012 3:37 PM
    Monday, April 30, 2012 3:37 PM
  • You can use e.g.  For i=1 to 2 step 0.

    This runs until stopped by ctrl C

    If you want to stop on something ocurring in the loop, I expect you

    can stop by setting I to 5 (unstested)

    Monday, April 30, 2012 5:19 PM
    Answerer
  • Setting I to 2 you mean.

    Monday, April 30, 2012 5:42 PM
  • Setting I to any value equal or greater then 2 works.

    Monday, April 30, 2012 6:00 PM
    Answerer
  • What about everything having ZEROs:

    For i=0 To 0 Step 0 Program.Delay(100) EndFor

    Assign any value greater than 0 to var i and break the loop.

    Or, use the old, simple, efficient Goto Loop!  ;-P

    Monday, April 30, 2012 7:59 PM
    Answerer
  • ForEach would require the idea of link-list iterators and complicate array element deletion (try deleting list elements in a foreach loop in VB), unnecessary complication - if you want these then its time to move to VB?

    For arrays with non integer indexes, use Array.GetAllIndices.

    For infinite loops I use:

    While ("True")
    ...
    EndWhile
    Any other examples where the syntax we already have isn't sufficient?
    Monday, April 30, 2012 8:55 PM
    Moderator