Write a program in C++ or Java which determines the scope of the control variable declared in a while loop. Your program must determine whether the control variable is visible after the loop’s body. Make sure that you compile and execute your program.
import java.util.*;
class ControlVar
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int sum=0;
while(true)
{
int a;
System.out.print("Enter the positive values of a (enter any
negative value to exit): ");
a=input.nextInt();
if(a<0)
{
break;
}
sum=sum+a;
}
System.out.println("Sum of the all a values: "+sum);
}
}
/*
The scope of the control variable declared in a while loop is private(local). So it means that you can declare a variable inside while loop but if you try to use that variable outside the loop then it will give or show the error, stating cannot find the symbol.
so The control variable is not visible after the loop's body.
*/
If a (control variable) is not used outside the while loop then it will not have the errors and executes perfectly.

But,
If a (control variable) is used outside the while loop then it will show the error, stating cannot find the symbol
Write a program in C++ or Java which determines the scope of the control variable declared...