Here is my code, im trying to call the variable defined inside the main(), but outside the current scope:
#include<iostream>
int main()
{
    int asd = 10;  //***
    while (True) 
    { 
        int asd = 100;
        asd -= 1;   //***is it possible to use the 'asd' defined before while loop
        if (asd ==0) break;
    }
}
best regards Eason
                        
No. The
int asd = 100;is masking the oldasdvariable.What you want (I suppose) is to just assign the value 100 to
asd, which (and I'm sure you know this) you could simply do by writingasd = 100;. There is, of course, one more issue: you would want to do that before thewhileloop - otherwise, you're going to have an infinite loop because at the beginning of every iteration the value ofasdwill be 100.You're missing a
;afterasd = 100, by the way.