Alternate for making such a thing work in perl : `for(10…0)`

后端 未结 3 1251
青春惊慌失措
青春惊慌失措 2021-01-18 02:20

This doesn\'t work in perl : for(10...0) It essentially doesn\'t loop even once, because it checks that 10>0 initially.

Any alternate s

3条回答
  •  爱一瞬间的悲伤
    2021-01-18 03:15

    for (reverse 0 .. 10) {
      say $_;
    }
    

    Use the reverse function.

    Unfortunately, this forces evaluation of the range to a list, so this uses more memory than the loop without reverse.

提交回复
热议问题