Why does this infinite loop happen?

0

I made this code but it is looping infinite and I can not fix it ...

#include <stdio.h>

int main (){
int x, z;

        while("x=100; x!=65; x-=5"){
            z=x*x;
            printf("%d --> %d\n", x, z);
        }
}
    
asked by anonymous 10.10.2017 / 05:17

1 answer

3

I'm pretty sure it's the quotes:

"x=100; x!=65; x-=5"

Remove them:

 while(x=100; x!=65; x-=5){

Values in quotation marks in C are char * , ie you did not pass variables, but char , and pro loop break need to pass a value like " false ", however while it does not work with ; , you probably want to use for :

for (x=100; x!=65; x-=5){
    z=x*x;
    printf("%d --> %d\n", x, z);
}

Or if it is while you can use it like this:

x=100;

while (x!=65){
    z=x*x;
    printf("%d --> %d\n", x, z);
    x-=5;
}
    
10.10.2017 / 05:20