vendredi 30 décembre 2016

How can I debug this FOR loop?

I am a beginner in C.

I have a program which is not working due to a for loop in it. I'm pasting a working snippet of code here (it is not the exact program)-

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int numLoop = 19;
    int counter;
    int maxloops = 25;
    int takenNum1 = 9, takenNum2 = 14, takenNum3 = 17, takenNum4 = 21, takenNum5 = 24;

    for (counter=1; counter==maxloops; counter++)
    {
        printf("%d \n", counter);

        if (counter == numLoop)
        {
            break;
        }

        if (counter == takenNum1 || counter == takenNum2 || counter == takenNum3 || counter == takenNum4 || counter == takenNum5)
        {
            counter++;
            continue;
        }
    }

    return 0;
}

The expected output is: 1 2 3 4 5 6 7 8 10 11 12 13 15 16 18 19

The output I am getting is: Literally nothing. Nothing is being printed.

How can I fix this?

Aucun commentaire:

Enregistrer un commentaire