DEV Community

Vignesh . M
Vignesh . M

Posted on

FLAG In Java

  • In Java programming, the term "flag" typically refers to a variable used as a signal or indicator within a program's flow. It's a common programming concept, not specific to Java, but widely applied in various contexts within Java development. Boolean Flags:
  • The most common type of flag is a boolean variable. It holds a true or false value, indicating whether a specific condition has been met or a particular state exists. Sample program :
boolean foundEven = false;
    for (int num : numbers) {
        if (num % 2 == 0) {
            foundEven = true; // Set the flag
            break;
        }
    }
    if (foundEven) {
        System.out.println("An even number was found.");
    }
Enter fullscreen mode Exit fullscreen mode

REFFERED LINKS:

  1. https://www.quora.com/How-can-the-flag-be-used-in-a-Java-program
  2. https://www.geeksforgeeks.org/use-of-flag-in-programming/

Top comments (0)