Can we use a variable assigned into while loop outside the loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we use a variable assigned into while loop outside the loop?

23rd Dec 2017, 6:36 AM
VINIT DEO
6 Answers
+ 6
Assigned yes, declared no. int a; while (condition) {a+=1;} int b = a; //will work while (condition) {int a =+1;} int b = a; //error
23rd Dec 2017, 6:38 AM
Dima Makieiev
Dima Makieiev - avatar
+ 3
Public or protected in this case not affect variable visibility scope.
23rd Dec 2017, 8:59 AM
Dima Makieiev
Dima Makieiev - avatar
+ 1
Just updated answer
23rd Dec 2017, 6:42 AM
Dima Makieiev
Dima Makieiev - avatar
0
can you please explain with help of example Dima
23rd Dec 2017, 6:42 AM
VINIT DEO
0
As @Dima said is correct
23rd Dec 2017, 6:52 AM
Mohamed
Mohamed - avatar
0
Even if you make it public?
23rd Dec 2017, 8:57 AM
Eremia Laurentiu
Eremia Laurentiu - avatar