Hello experts,
actually i have a situation like this.
i have a drop down menu value:{2,3,4,5,6}. there is a common operation need to be done if any number in menu list chosen.each of the number must have different number of layers. if user choose 2 means 2 layers,if 3 means 3 layers and so on. this is my plan.
comb[0] is layer

for(int i=0;i<comb[0];i++)
 for(int j=0;j<comb[1];j++)
  { if(value_int==2)  goto A:
     else for(int k=0;k<comb[2];k++)
           { if(value_int==3)  goto A:
             else for(int l=0;k<comb[3];k++)
                   { if(value_int==4)  goto A:
                     else for(int m=0;k<comb[4];k++)
                           { if(value_int==5)  goto A:
                             else for(int n=0;k<comb[5];k++)
                                  goto A:
                            }
                   }
            }
   }

A: //do A

so, my question is,can i use goto? or it is not available in java?
or mayb u have any suggestion to my code?i knew its not a good way to be done.
really need help for this guys!!!

Thanks for advance.

Re: is 'go to' in java availabe? 80 80

There is no goto keyword in java that will take you to a certain line. According to wikipedia the goto keyword is reserved in java but not actually used.

So, goto is not a choice.. changing the code should be though. i'll leave that to someone a little more equipped when it comes to java though :P

Re: is 'go to' in java availabe? 80 80

There is no goto keyword in java that will take you to a certain line. According to wikipedia the goto keyword is reserved in java but not actually used.

So, goto is not a choice.. changing the code should be though. i'll leave that to someone a little more equipped when it comes to java though :P

any suggestion to my program?

Re: is 'go to' in java availabe? 80 80

no it's not in JAVA

Re: is 'go to' in java availabe? 80 80

Use methods. Your example and explanation are convoluted and I can't give more specific advice, but to "do something" under certain conditions (i.e. in a control structure such as a for loop, if statement, etc) you can call a method.

Re: is 'go to' in java availabe? 80 80

Use methods. Your example and explanation are convoluted and I can't give more specific advice, but to "do something" under certain conditions (i.e. in a control structure such as a for loop, if statement, etc) you can call a method.

i understand u.but can i use 'for' more than 2 times?

Re: is 'go to' in java availabe? 80 80

Hello experts,
actually i have a situation like this.
i have a drop down menu value:{2,3,4,5,6}. there is a common operation need to be done if any number in menu list chosen.each of the number must have different number of layers. if user choose 2 means 2 layers,if 3 means 3 layers and so on. this is my plan.
comb[0] is layer

for(int i=0;i<comb[0];i++)
 for(int j=0;j<comb[1];j++)
  { if(value_int==2)  goto A:
     else for(int k=0;k<comb[2];k++)
           { if(value_int==3)  goto A:
             else for(int l=0;k<comb[3];k++)
                   { if(value_int==4)  goto A:
                     else for(int m=0;k<comb[4];k++)
                           { if(value_int==5)  goto A:
                             else for(int n=0;k<comb[5];k++)
                                  goto A:
                            }
                   }
            }
   }

A: //do A

so, my question is,can i use goto? or it is not available in java?
or mayb u have any suggestion to my code?i knew its not a good way to be done.
really need help for this guys!!!

Thanks for advance.

actually its like more than double array..i dont know how to tell it.
example when user choose 2 from dropdown menu.
array a[0]= 0,1,1 array b[0]=0,1,2
a[1]= 1,0,1 b[1]=0,1,2
a[2]= 1,1,0 b[2]=0,1,2


for a[0][2], it must list all in b[2]
a[0][1], it must list all in b[1]
a[0][0], randomly choose data in b[0]
for a[1][2], it must list all in b[2]
a[1][1], randomly choose data in b[1]
a[1][0], it must list all in b[0]
for a[2][2], randomly choose data in b[2]
a[2][1], it must list all in b[1]
a[2][0], it must list all in b[0]

and so on with value=3,4,5,6 the different is the size of both a and b array. for array a, value=number of '1' and b must be more than value

Re: is 'go to' in java availabe? 80 80

no,,, use loop is just the same as go to but it has a condition...

Re: is 'go to' in java availabe? 80 80

no,,, use loop is just the same as go to but it has a condition...

could u please elaborate more?please...

Re: is 'go to' in java availabe? 80 80

here a sample:
I don't know if this is what you need
I use "goto" when I'm using/putting a choice in my program
just like the below example....

hope this help...

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class sample {
	public static void main( String[] args ) {
		try {
			char choi;
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			do {
				System.out.print("Enter your name: ");
				String name = input.readLine();
				System.out.println(name);
				System.out.print("Try again?Y/N");
				choi = (char) input.read();
			} while(choi=='Y' || choi=='y');
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
Re: is 'go to' in java availabe? 80 80

or how about use a function,,,,

public static void A() {
     //code here
}


///////////////////////

for(int i=0;i<comb[0];i++)
 for(int j=0;j<comb[1];j++)
  { if(value_int==2)  goto A:
     else for(int k=0;k<comb[2];k++)
           { if(value_int==3)  A();
             else for(int l=0;k<comb[3];k++)
                   { if(value_int==4)  A();
                     else for(int m=0;k<comb[4];k++)
                           { if(value_int==5) A();
                             else for(int n=0;k<comb[5];k++)
                                 A();
                            }
                   }
Re: is 'go to' in java availabe? 80 80

try this code

break A:
Re: is 'go to' in java availabe? 80 80

you can throw some Exception and handle it instead of

goto A:
Re: is 'go to' in java availabe? 80 80

but goto is deprecated in java. its not recommended to use goto

commented: utterliy and completely wrong -2
Re: is 'go to' in java availabe? 80 80

but goto is deprecated in java. its not recommended to use goto

Wrong. So utterly wrong I can't begin to describe it.
Goto is NOT deprecated.
It is a reserved word that was never implemented.

This was done quite deliberately because there's never a need for goto.
Any programmer who thinks they need it have serious design flaws and need to rethink their architecture, start to learn programming Java rather than Basic.

Loops, methods, etc. are where it's at, not random jumping around in code.

Re: is 'go to' in java availabe? 80 80

ok i might be wrong.
but still if you want to implement it.

break A; //semicolon at the end
Re: is 'go to' in java availabe? 80 80

Thanks guys...so much.
I think i prefer use method...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.