我的程序不会停止执行 if 语句但条件不满足

My program won't stop executing the if statement yet the condition is not met

它应该是 x 轴上 1 到 6 和 y 轴上 1 到 5 的乘法 table,所以我有这个 if 语句,一旦乘法达到 6 但它继续执行,即使我重置了其中要满足的条件。

#include <stdio.h>
#include <stdlib.h>
int main(){
int mult = 1;
int check = 0;
int res;
while(mult != 6){


        if (check <= 6){
            res = mult * check;
            printf("%d ",res);
            check ++;
        }
        if (check > 6 ){
            printf("\n ");
            check = 0;
        }

}}

if语句让你执行或不执行一个块。

例如,在您的代码中:

if (check <= 6){
    res = mult * check;
    printf("%d ",res);
    check ++;
}
if (check > 6 ){
    printf("\n ");
    int check = 0;
}

第一个块将在check <= 6时执行,第二个块将在check > 6时执行...但是while循环中的条件是mult != 5 ...并且您永远不会修改 mult,因此条件始终为真。

因此,除了 uZuMaKioBaRuTo 对您的 check 变量的评论外,您还需要增加 mult:

if (check > 6 ){
    printf("\n ");
    check = 0;
    mult++;
}