所以我创建了一个方法,使用多个for循环,我正在寻找一种方法,我可以让前面的for循环停止运行,以便我可以开始使用下一个。这里是我的代码:如何停止for循环运行?
public void timePasses()
{
House callgo = new House();
System.out.println("Shower usage:\n");
for (int x = 0; x < 4; x++)
{
callgo.goShower();
//Need to stop here, System.out.println("Cooker usage:\n"); only needs to print once.
System.out.println("Cooker usage:\n");
for (int z = 0; z < 4; z++)
{
callgo.goCooker();
}
//this method is called as part of the simulation to trigger a new fifteen minute period
//in the house. When it is called, it will in turn call timePasses() on all the Appliances in the House.
}
}
我知道,这将有可能只是使用多种方法,但进行了规范,我需要一个timePasses()
方法中打印出所有的数据,所以我在想,如果有一个我可以停止以前的循环运行,打印出我的声明并开始下一个?任何帮助表示赞赏,谢谢。
是不是因为你封闭在第一个第二循环? – GurV
那是因为那个。 – Ben