Useful alternative control structures?

后端 未结 28 928
礼貌的吻别
礼貌的吻别 2021-01-30 02:20

Sometimes when I am programming, I find that some particular control structure would be very useful to me, but is not directly available in my programming language. I think my

28条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 03:07

    How about PL/I style "for" loop ranges? The VB equivalent would be:

    ' Counts 1, 2, ... 49, 50, 23, 999, 998, ..., 991, 990
      For I = 1 to 50, 23, 999 to 990 Step -1
    

    The most common usage I can see would be to have a loop run for a list of indices, and then throw in one more. BTW, a For-Each usage could also be handy:

    ' Bar1, Bar2, Bar3 are an IEnum(Wazoo); Boz is a Wazoo
      For Each Foo as Wazoo in Bar1, Bar2, Enumerable.One(Boz), Bar3
    

    This would run the loop on all items in Bar1, all items in Bar2, Boz, and Bar3. Linq would probably allow this without too much difficulty, but intrinsic language support might be a little more efficient.

提交回复
热议问题