Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a boolean flag

I'm taking a course in Visual Basic 2010 and I'm trying to get a grasp on this new term called a flag. I kind of understand that it has something to do with a boolean condition. I don't quite understand what a flag is. I see references to it using the term flag. I understand it has something to do when a boolean, a condition triggers a flag. But what is the flag. How do you identify it? Can somebody give me an example.

like image 744
swydell Avatar asked Oct 03 '11 01:10

swydell


People also ask

What does a Boolean flag do?

 A Flag is a boolean variable that signals when some condition exists in a program.  When a flag is set to true, it means some condition exists  When a flag is set to false, it means some condition does not exist. if(score > 95) highscore = true;  Here, highscore is a flag indicating that the score is above 95.

What is a Boolean flag in C?

A boolean is a data type in the C Standard Library which can store true or false . Every non-zero value corresponds to true while 0 corresponds to false . The boolean works as it does in C++. However, if you don't include the header file​ stdbool. h , the program will not compile.

What are Boolean flags in Python?

The Python Boolean type is one of Python's built-in data types. It's used to represent the truth value of an expression. For example, the expression 1 <= 2 is True , while the expression 0 == 1 is False .

What is Boolean flag in Java?

A Boolean expression is a Java expression that returns a Boolean value: true or false . This is useful when we want to compare values to find answers.


1 Answers

In general, "Flag" is just another term for a true/false condition.

It may have more specific meanings in more specific contexts. For instance, a CPU may keep "arithmetic flags", each one indicating a true/false condition resulting from the previous arithmetic operation. For instance, if the previous operation was an "ADD", then the flags would indicate whether the result of the add was zero, less than zero, or greater than zero.

I believe the term comes from flags used to signal a go/no go condition, like, a railroad flagman indicating whether or not it is safe for the train to proceed.

like image 172
John Saunders Avatar answered Sep 28 '22 03:09

John Saunders