Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize a local variable in its declaration in Eiffel?

I tried to do this:

local
    condition: BOOLEAN
    condition := true
do

And something like this:

local
    condition: BOOLEAN := true
do

Obviously neither work, but I need to initialize a variable inside the declaration because I don't want the variable to re-initialize if a retry instruction is executed. I looked in Eiffel's oficial documentation and in tutorial but they always intitialize variables in the body of the operation.

like image 530
Rama Avatar asked Feb 23 '23 10:02

Rama


1 Answers

Every variable is initialised in Eiffel, so in local they all get their default value, which is false for BOOLEAN.

Note that for a retry the variables are not initialised to their default again, so you can use that with:

test
  local
    retrying: BOOLEAN
  do
    if retrying then
      do_something_else
    else
      retrying := true
      first_try
    end;
  rescue
    handle_error
    retry
  end
like image 198
Berend de Boer Avatar answered May 18 '23 23:05

Berend de Boer