Branch if int
comparison with zero succeeds
Bytecode
Type | Description |
u1 | ifeq opcode = 0x99 (153) |
s2 | branchoffset |
Type | Description |
u1 | ifne opcode = 0x9A (153) |
s2 | branchoffset |
Type | Description |
u1 | iflt opcode = 0x9B (153) |
s2 | branchoffset |
Type | Description |
u1 | ifge opcode = 0x9C (153) |
s2 | branchoffset |
Type | Description |
u1 | ifgt opcode = 0x9D (153) |
s2 | branchoffset |
Type | Description |
u1 | ifle opcode = 0x9E (153) |
s2 | branchoffset |
The value must be of type int
. It is popped from the operand stack
and compared against zero. All comparisons are signed. The results of the comparisons are
as follows:
If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this if<cond> instruction. The target address must be that of an opcode of an instruction within the method that contains this if<cond> instruction.
Otherwise, execution proceeds at the address of the instruction following this if<cond> instruction.
Example
iload_1
; push the int value in local variable 1
onto the stack
ifeq Label ; if the value of local
variable 1 is zero, jump to Label
return ; return
if local variable 1 is nonzero
Label:
; execution continues here if local variable 1 equals zero...
Notes
Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).