I was trying to get an infinite addition calculation .When I compile this code I get unreachable statement that I believe it been caused by different statement levels .
import java.util.Scanner;
public class infiAdd {
public static void main (String [] args ){
int a;
char ans;
int c=0;
Scanner input;
input=new Scanner(System.in);
Bag: for(;;) {
System.out.print("Please enter a number:");
a=input.nextInt();
Bag2:for(;;) {
System.out.println("Do you wnat to add more ?[y/n]");
ans=input.next().charAt(0);
while (!(ans=='y')) {
while(!(ans=='n')){
System.out.println("Please enter a valid answer!");
continue Bag2;
}
c=c+a;
System.out.println("The result is :"+c);
}}
c=a+c;
continue Bag;}
}
}
The unreachable statement is c=a+c;