On Mon, Oct 12, 2015 at 1:35 PM, Ralf Quint <freedos...@gmail.com> wrote:

>
> Either the while loop is executed or it isn't, depending in the
> expression. I don't see an actual use case for any else/otherwise extension
> to it...
>

You probably want to reread python while-else implementation. (
https://docs.python.org/2/reference/compound_stmts.html)
"Else" becomes sort of "part of the loop". Thus if you break out of the
loop, "else" would not be executed.
However, if no break occurs "else" part would be executed.

It might be a rare case where it's needed. (I cannot think of any), but to
achieve exactly the same functionality in Pascal either of two options
should be used.

1) make an extra check if break occurred.

breakflag:=false;

while cond do
  if someothercond then begin
    breakflag : =true;
    break;
  end;

if not breakflag then
  while_else_code

2) use goto! :)

label postElseLabel

while cond do
  if someothercond then begin
     goto  postElseLabel
  end;

while_else_code
:postElseLabel

thanks,
Dmitry
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to