循环导致无法到达的断点

Loop causing unreachable breakpoints

我正在尝试用 C++ 复制 Luhn 算法,但我遇到了问题。如您所见,我有两个 for 循环。在 MSVC 中,如果我在第二个 for 循环中放置断点,甚至在 return 上放置断点,MSVC 会告诉我不会命中断点。

是什么导致了这个问题?

int luhn_checksum(std::vector<int> cardnumber[NUMBER_OF_DIGITS - 1]) {
    //step 1: duouble every second number
    for (int i = 1; i < NUMBER_OF_DIGITS; i + 2) {
        new_digits[i] = digits[i] * 2;
        if (new_digits[i] > 9) {
            //if the product is larger than 9 we will add the two numbers together
            //example: 9 * 2 = 18 so we will add 1 + 8 to get 9
            tmp1 += new_digits[i] % 10;
            new_digits[i] /= 10;
            tmp1 = 0;
        }
    }

    //step 2: sum all the values
    for (int i = 0; i < NUMBER_OF_DIGITS; ++i) {
        checksum += new_digits[i];
    }

    return checksum;
}

在第一个for循环中你没有递增 所以替换

for (int i = 1; i < NUMBER_OF_DIGITS; i += 2)

如果你想增加 2