循环导致无法访问的断点

Loop causing unreachable breakpoints

本文关键字:访问 断点 循环      更新时间:2023-10-16

我正试图在C++中复制Luhn算法,但遇到了一个问题。正如你所看到的,我有两个for循环。在MSVC中,如果我在第二个for循环中放置一个断点,或者甚至在返回时,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