Statement expected but Function found error in my function code

三世轮回 提交于 2020-01-06 04:43:06

问题


So below is the module of code I have created to verify a user input is between a range but this error keeps appearing below it ' statement expected but function found', any ideas anyone? Many thanks

function get_choice(var Options: integer): integer;
      var
      choice: integer;

      begin
        while (true) do
          begin
              write('choose option 1 to', Options);

              try
                readln(choice);
                if (choice>=1) and (choice <=Options) then
                    get_choice := choice
                else
                    write('invalid range');
              except
                 write('not a number');
          end;
      end;

回答1:


You missed an end:

              try
                readln(choice);
                if (choice>=1) and (choice <=Options) then
                    get_choice := choice
                else
                    write('invalid range');
              except
                 write('not a number');
              end;
         end
      end;

Try try..except block must have its own end.




回答2:


As Sharam already stated, you missed the end of the try..except..end block. Nevertheless, I think I can enhance the answer a bit with some tips, to help avoiding this in you future.

  • keep your (begin .. end blocks on the same column. Same for try..except..end, try..finally..end and repeat..until blocks off course.
  • make use of the IDE's option to connect the begin and and blocks with lines. "structural highlighting. Check the attached screenshots.



来源:https://stackoverflow.com/questions/50855823/statement-expected-but-function-found-error-in-my-function-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!