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:
- Checks if an image exists on screen
- 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:
- First condition is checked
- If false, second condition is checked
- 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:
- Checking for an image
- Showing one alert if found
- 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