Your for-loop is wrong. The loop will only execute while the condition between the semicolons is true. Converting your for-loop to the exact equivalent while loop produces:
i = ndigit;
...