Topic: 我有落程序编译总是报错!(新手有问题,请教大家)

  Print this page

1.我有落程序编译总是报错!(新手有问题,请教大家) Copy to clipboard
Posted by: huangfight
Posted on: 2004-05-19 17:56

public class good
{
  public static void main(String args[])
  {
    int i=2;
    fei:
    System.out.println("It's good!");
    gogo:
    while(true)
    {
      if(i>1)break fei;break gogo;
    }
    System.out.println("Oh ye!");
    System.out.println("That's ok!");
  }
}

H:\JCreator Pro\MyProjects\good.java:11: undefined label: fei
      if(i>1)break fei;break gogo;

编译程序总是报错说:没有定义fei.但是我明明在前面定义了呀?
请大家指教指教!谢谢了!

2.Re:我有落程序编译总是报错!(新手有问题,请教大家) [Re: huangfight] Copy to clipboard
Posted by: taogang
Posted on: 2004-05-19 21:58

read again the "Controlling Program Flow" of "Think in Java" and be aware of that you are using JAVA but C/C++.

it says:

The only place a label is useful in Java is right before an iteration statement. And that means right before—it does no good to put any other statement between the label and the iteration. And the sole reason to put a label before an iteration is if you’re going to nest another iteration or a switch inside it. That’s because the break and continue keywords will normally interrupt only the current loop, but when used with a label, they’ll interrupt the loops up to where the label exists

3.Re:我有落程序编译总是报错!(新手有问题,请教大家) [Re: huangfight] Copy to clipboard
Posted by: whirl79
Posted on: 2004-05-19 22:24

帅哥,你要这样定义String fei ="";String gogo="";才行


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923