语法标签错误

时间:2013-05-07 05:43:52

标签: java label syntax-error

我有这部分代码给我带来了麻烦:

  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();

我在label215label136以及label75后出现语法错误,需要分号预期赋值运算符才能完成语句。那是为什么?

1 个答案:

答案 0 :(得分:1)

标签仅在2种情况下有效:

  • 在for循环,while循环或do-while循环中使用它时。例如:
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
}
  • 在代码块上使用它时。例如:
label:
{
   // do something
   if(someCondition) break label;
   // rest of code
}