user2356014
user2356014

Reputation: 1

Syntax Error in label

I have this part of code which is giving me trouble:

  Iterator localIterator1;
  label75: 
  Iterator localIterator2;
  if (str1 != null)
  {
    localIterator1 = localArrayList.iterator();
    boolean bool = localIterator1.hasNext();
    j = 0;
    if (bool)
      break label136;
    if (j == 0)
    {
      localIterator2 = localArrayList.iterator();
      label86: if (localIterator2.hasNext())
        break label215;
    }
  }
  while (true)
  {
    if (i != 0)
      MySpeechRecogonizer.this.position = 0;
    if ((j == 0) || (MySpeechRecogonizer.this.matchListener == null))
      break label404;
    MySpeechRecogonizer.this.matchListener.onSpeechMatch();
    return;
    label136:String str2 = (String)localIterator1.next();
    Log.e(MySpeechRecogonizer.this.TAG, str2 + MySpeechRecogonizer.this.target);
    if (!str2.trim().replace(" ", "").contains(MySpeechRecogonizer.this.target))
      break;
    j = 1;
    break label75;
    label215:
        String str3 = (String)localIterator2.next();

I get syntax error after label215, label136 and moreover label75, with either semicolon expected or assignment operator needed to complete statement. Why is that?

Upvotes: 0

Views: 342

Answers (1)

Eng.Fouad
Eng.Fouad

Reputation: 117587

Labels are only valid in 2 contexts:

  • When using it within for-loop, while-loop, or do-while-loop. For example:
label:
for(int i = 0; i < listA.size(); i++)
{
    // doSomething
    while(someCondition)
    {
        // do another thing
        if(conditionA) continue label;
        if(conditionB) break label;
        // rest of code
    }
    // another code
}
  • When using it on a block of code. For example:
label:
{
   // do something
   if(someCondition) break label;
   // rest of code
}

Upvotes: 1

Related Questions