4

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.

Rama
  • 4,697
  • 5
  • 22
  • 19

3 Answers3

8

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
Berend de Boer
  • 1,953
  • 20
  • 15
0

I think you can use

local
condition: BOOLEAN = true
do
lucidbrot
  • 5,378
  • 3
  • 39
  • 68
0
local
   condition: BOOLEAN
do
   condition := True
   ...
Jocelyn
  • 693
  • 5
  • 8