Article ID: 10151
PRB: In-Prompt Script IF/ELSE/ELSEIF/ENDIF nesting problem.
PROBLEM
Applies To: ITScriptNet V1/V2
Writing an In-Prompt Script that contains nested IF/ELSEIF/ELSE/ENDIF blocks may result in the execution of script lines that should not have been run. For example, this script code:
@param1@ = 1
@param2@ = 1
@ret@ = "A"

if(@param1@ = 0)
  @ret@ = @ret@ & "B"

  if(@param2@ = 0)
   @ret@ = @ret@ & "!"
 elseif(@param2@ = 1)
   @ret@ = @ret@ & "@"
 elseif(@param2@ = 2)
   @ret@ = @ret@ & "#"
 else
   @ret@ = @ret@ & "$"
 endif

elseif(@param1@ = 1)
  @ret@ = @ret@ & "C"

  if(@param2@ = 0)
    @ret@ = @ret@ & "!"
  elseif(@param2@ = 1)
    @ret@ = @ret@ & "@"
  elseif(@param2@ = 2)
    @ret@ = @ret@ & "#"
  else
    @ret@ = @ret@ & "$"
  endif

elseif(@param1@ = 2)
  @ret@ = @ret@ & "D"

  if(@param2@ = 0)
    @ret@ = @ret@ & "!"
  elseif(@param2@ = 1)
    @ret@ = @ret@ & "@"
  elseif(@param2@ = 2)
    @ret@ = @ret@ & "#"
  else
    @ret@ = @ret@ & "$"
  endif

else
  @ret@ = @ret@ & "E"

  if(@param2@ = 0)
    @ret@ = @ret@ & "!"
  elseif(@param2@ = 1)
    @ret@ = @ret@ & "@"
  elseif(@param2@ = 2)
    @ret@ = @ret@ & "#"
  else
    @ret@ = @ret@ & "$"
  endif

endif

Message(@ret@, "Result", "OK", "")
Running with @param1@ = 1 and @param2@ = 1 should result in the string 'AC@'. However, the string 'AC@E@' is returned. Other combinations of Parameter1 and Parameter2 work correctly. The problem only occurs if the first ELSEIF is true for each nested block.
RESOLUTION
There is a problem in ITScriptNet versions prior to 2.3 that result in this issue. It has been corrected in version 2.3a.
This article last updated: 1/1/2009 12:00:00 AM
Please help us improve the Knowledge Base by rating this article.
    © 1997-2026 Z-Space Technologies - a BCA Innovations Company - All rights reserved