請問在void裡面的return指令有什麼用途
這個是河內之塔遊戲的解法一部份
------------------------------------------------------------------------
class HanoiTowerGame {
void go(int discs) {
hanoiTower('A', 'C', 'B', discs);
}
void moveDisc(char source, char target, int disc) {
System.out.println("Move No." + disc + " disc from " + source + " to " + target);
}
void hanoiTower(char a, char c, char b, int discs) {
System.out.println("discs = " + discs);
if(discs == 1) {
moveDisc(a, c, discs);
return;
}
hanoiTower(a, b, c, discs - 1);
moveDisc(a, c, discs);
hanoiTower(b, c, a, discs - 1);
}
}
------------------------------------------------------------------------
說明上所指這個指令是為了跳出控制區塊
但小弟不明白用意
希望可以詳細講解一下
謝謝!!!