Making code shorter

后端 未结 5 641
感动是毒
感动是毒 2021-01-26 16:28

I\'m currently building a program and I\'m trying to make my code a bit shorter. It\'s just a for-loop repeating itself 15 times. Can someone show me how they would do it and ex

5条回答
  •  醉酒成梦
    2021-01-26 16:46

    You need to think about what loops are for.

    This is trivial to refactor, really. You have the exact same code repeating 16 times. So:

    for (int k = 0; k < 16; k++) {
        // your inner, repeating loop here
    }
    

提交回复
热议问题