IF

Specify a condition within a batch file.

Syntax

IF condition THEN commandlist; [ELSE commandlist] END

Parameters

condition

May contain relations or logical expressions as used within the C/C++ programming language. See also Combining Elements. Debugger variables are also permitted as operands. For example:

IF @x == @y THEN …

or

IF @x == 0 && @x != a+1 THEN …

where @x and @y are debugger variables.

commandlist

A list containing one or more debugger commands separated by semicolons “;”. For example:

…THEN EVAL @x END

or

…THEN EVAL @x; STEP 2; EVAL @y END

Description

This command is used within batch files. It is used to specify a condition. If the condition is true, the command list between THEN and ELSE (or THEN and END if ELSE is omitted) is executed. If the condition is not true (= 0), the optional ELSE-part is executed. IF commands may be used nested (complex if-structures) as well. If the IF command is used with a command list, the keyword END must be terminated with a semicolon. See examples.

Example

! Example batch file if.xdb
set val @input = 0
while 1 then
set val @input = @input + 1
eval @input
! Condition: if @input is equal to 5 then break
if @input == 5 then break end
end

The following example demonstrates an IF command within a command list directly entered in the Console window:

xdb> STEP 2; IF x == 3 THEN BREAK; ELSE STEP 5 END; EVAL x

The following example demonstrates IF and ELSE IF:

! Example for IF and ELSE IF; example batch file ifelse.xdb
set val @input = 0
while 1 then
set val @input = @input + 1
eval @input
! Condition 1
  if @input < 5 
      then
        print "<@input> is lower than 5\n"
      else
! Condition 2
        if @input == 5
          then print "<@input> equals 5\n";break
        end
  end
end

The last example demonstrates a complex if-structure which is used within a batch file:

! Example batch file test.xdb
  
SET BREAK AT BREA1\@line 15
SET BREAK AT BREA1\@line 14 CONTINUE
STEP
WHILE i < 10 
  THEN 
     EVAL i
     IF i==3
       THEN
       IF j==3
         THEN
         IF k==3
           THEN 
           IF l==3
             THEN
             DISABLE BREAK AT BREA1\@line 14
             DISABLE BREAK AT BREA1\@line 15
             SET BREAK AT BREA1\@line 17 CONTINUE
             SET BREAK AT BREA1\@line 18 
             BREAK
           END
         END
       END
     END
IF i==4
   THEN
   EXIT
END 
RUN
END 

See Also

For more complete information about compiler optimizations, see our Optimization Notice.