What does while (x--) mean in C language?

1

I came across this code and I did not understand the while(a--) loop, what does it mean?

int main(){
     char pisca[10], a = 3;
     short numero;

     while(a--){
         numero = 0;

         while(1){
             scanf("%s caw", pisca);

             if(!strcmp(pisca, "caw")) break;

             if(pisca[0] == '*') numero += 4;
             if(pisca[1] == '*') numero += 2;
             if(pisca[2] == '*') numero += 1;

         } 

         printf("%hd\n", numero);
     }

     return 0;
}
    
asked by anonymous 08.04.2018 / 05:53

2 answers

5

Let's start with the expression inside while : a-- is the same as a = a - 1 .

I imagine you know what while does. Every time you pass through it, you will run that expression, so each time the variable a has subtracted 1. Until you reach 0.

The while executes while it is true, or any number other than 0. When it reaches zero it is considered false and therefore the loop should be terminated.

    
08.04.2018 / 06:06
-3

The implicit condition of while is "! = 0" o "a -" is not testing anything.

    
08.04.2018 / 06:13