-2

I am currently trying to create a string of code that if something is true it will go to a certain line in the code... ex:

1  boolean hi = true;
2  boolean hey = true;
3
4  if(hi){
5  hi=false;
6  System.out.println("HI");
7  }
8  
9  if(hey=true){
10  hi=true;
11  hey=false;
12  //GO BACK TO LINE 3
13 }
14

That is a much simpler version of what im trying to do so if you have any ways to do this please help me

NalydZ
  • 21
  • 4

1 Answers1

0

Without being biased - the equivalent feature is to use labels. But labels can only be branched to from within a looping structure like "while".

boolean hi = true;
boolean hey = true;

line3:
while (true) {
 if(hi){
  hi=false;
  System.out.println("HI");
  }

  if(hey){
      hi=true;
      hey=false;

      break line3;
  }
}
prabodhprakash
  • 3,825
  • 24
  • 48
fedup
  • 1,209
  • 11
  • 26