Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
在 c 裡,一個函數隨時都可用 return 來做中止並傳回值,那請問在 Pascal裡,我該如那個KeyWord 在程序中提早結束程式或在函數中,提早結束並回傳?
想要中途跳離 Procedure 或 Function 可以用 Exit; 這個程序
function Test(i: integer): string; begin Result := IntToStr(i) + ' = 0'; if i > 0 then begin Result := IntToStr(i) + ' > 0'; Exit; end; if i < 0 then begin Result := IntToStr(i) + ' < 0'; Exit; end; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(Test(0)); end;
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |