MNY
MNY

Reputation: 1536

Why is the while loop is not stoping after the last statement?

In the next program the while loop suppose to stop after the printf in the block is executed:

isn't it?

#include <stdio.h>
#define HOUR 60

int main()

{

    int min, smallThenHour, timeInHour, minLeft;

    printf("please enter time in minutes: \n");

    scanf("%d", &min);

    while (min > 0)

    {
        timeInHour = min/HOUR;
        minLeft = min % HOUR;
        smallThenHour = min < HOUR;

        printf("in %d seconds, there are %d and %d min",min, timeInHour,smallThenHour);
    }

}

Would appreciate is someone can tell a c beginner why its not stopping :)

tnx

Upvotes: 1

Views: 76

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477514

Because you never change the value of min inside the loop body. Once the condition is true, it always remains true.

Upvotes: 7

Related Questions