Skip to main content

If, Else If, Else

In Android Macro, conditional statements are used to perform different actions based on different conditions. The most common form of conditional statements are the if, else if, and else statements.

If Statement

The if statement is used to execute a block of code only if a specified condition is true.

The example above shows a basic if statement that:

  1. Checks if an image exists on screen
  2. If true, performs a click action at coordinates (500,500)

Else If Statement

The else if statement allows you to test multiple conditions in sequence.

In this example:

  1. First condition is checked
  2. If false, second condition is checked
  3. Different actions are performed based on which condition is true

Else Statement

The else statement executes when none of the previous conditions are true.

This example shows:

  1. Checking for an image
  2. Showing one alert if found
  3. Showing a different alert if not found

Common Uses

Conditional statements are useful for:

  • Checking if elements exist before interacting with them
  • Creating different paths based on screen states
  • Handling errors and edge cases
  • Making macros more robust and adaptable

Tips

  • Always test your conditions thoroughly
  • Use clear, logical conditions
  • Consider all possible scenarios
  • Add appropriate delays when needed
  • Use else statements as fallbacks