What is a flag variable?
up vote
6
down vote
favorite
Recently I just came across this term and I had no idea as to what purpose it serves?
I am little unsure about when to use a flag variable and how to go about it?
I Googled it but there were not any specific examples related to it (in the context of JavaScript).
javascript variables flags
add a comment |
up vote
6
down vote
favorite
Recently I just came across this term and I had no idea as to what purpose it serves?
I am little unsure about when to use a flag variable and how to go about it?
I Googled it but there were not any specific examples related to it (in the context of JavaScript).
javascript variables flags
Asked and answered here: stackoverflow.com/questions/1626263/enum-flags-in-javascript
– Bill Gregg
Jul 1 '13 at 10:23
my first hit in google javascriptkit.com/javatutors/valid2.shtml
– Vignesh Vino
Jul 1 '13 at 10:24
look at that example,its pretty confusing!!!
– JETHALAL
Jul 1 '13 at 10:24
add a comment |
up vote
6
down vote
favorite
up vote
6
down vote
favorite
Recently I just came across this term and I had no idea as to what purpose it serves?
I am little unsure about when to use a flag variable and how to go about it?
I Googled it but there were not any specific examples related to it (in the context of JavaScript).
javascript variables flags
Recently I just came across this term and I had no idea as to what purpose it serves?
I am little unsure about when to use a flag variable and how to go about it?
I Googled it but there were not any specific examples related to it (in the context of JavaScript).
javascript variables flags
javascript variables flags
edited Aug 9 '14 at 19:46
Danny Beckett
13.5k1875119
13.5k1875119
asked Jul 1 '13 at 10:20
JETHALAL
8,129143665
8,129143665
Asked and answered here: stackoverflow.com/questions/1626263/enum-flags-in-javascript
– Bill Gregg
Jul 1 '13 at 10:23
my first hit in google javascriptkit.com/javatutors/valid2.shtml
– Vignesh Vino
Jul 1 '13 at 10:24
look at that example,its pretty confusing!!!
– JETHALAL
Jul 1 '13 at 10:24
add a comment |
Asked and answered here: stackoverflow.com/questions/1626263/enum-flags-in-javascript
– Bill Gregg
Jul 1 '13 at 10:23
my first hit in google javascriptkit.com/javatutors/valid2.shtml
– Vignesh Vino
Jul 1 '13 at 10:24
look at that example,its pretty confusing!!!
– JETHALAL
Jul 1 '13 at 10:24
Asked and answered here: stackoverflow.com/questions/1626263/enum-flags-in-javascript
– Bill Gregg
Jul 1 '13 at 10:23
Asked and answered here: stackoverflow.com/questions/1626263/enum-flags-in-javascript
– Bill Gregg
Jul 1 '13 at 10:23
my first hit in google javascriptkit.com/javatutors/valid2.shtml
– Vignesh Vino
Jul 1 '13 at 10:24
my first hit in google javascriptkit.com/javatutors/valid2.shtml
– Vignesh Vino
Jul 1 '13 at 10:24
look at that example,its pretty confusing!!!
– JETHALAL
Jul 1 '13 at 10:24
look at that example,its pretty confusing!!!
– JETHALAL
Jul 1 '13 at 10:24
add a comment |
3 Answers
3
active
oldest
votes
up vote
11
down vote
accepted
Flag Variables Defined and Uses says:
A flag variable, in its simplest form, is a variable you define to have one value until some condition is true, in which case you change the variable's value. It is a variable you can use to control the flow of a function or statement, allowing you to check for certain conditions while your function progresses.
As an example:
// errors is the flag var
var errors = 0;
for(var i = 0; i < 10; i++)
if(i == 6) // your error condition
errors++;
if(errors) // is the flag "up"? (i.e. > 0)
alert("There was a problem!");
add a comment |
up vote
2
down vote
A flag is a variable used to have some value until some condition becomes true,then we change it to false and print the output (Initially flag considered as true)
5
Please expand and give a code example.
– Dementic
Jan 2 '14 at 12:13
add a comment |
up vote
0
down vote
Flag variables are the same for all languages, whether it's RUBY or Python or JavaScript or C++ or even Microsoft® Small Basic™.
A flag variable is usually given two values 0 and 1. So, its used as a Boolean variable where the result toggles between 0 (False) and 1 (True) or as used by the programmer. Some prefer flag=1 and change it to flag=0 in the program to perform an action.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
accepted
Flag Variables Defined and Uses says:
A flag variable, in its simplest form, is a variable you define to have one value until some condition is true, in which case you change the variable's value. It is a variable you can use to control the flow of a function or statement, allowing you to check for certain conditions while your function progresses.
As an example:
// errors is the flag var
var errors = 0;
for(var i = 0; i < 10; i++)
if(i == 6) // your error condition
errors++;
if(errors) // is the flag "up"? (i.e. > 0)
alert("There was a problem!");
add a comment |
up vote
11
down vote
accepted
Flag Variables Defined and Uses says:
A flag variable, in its simplest form, is a variable you define to have one value until some condition is true, in which case you change the variable's value. It is a variable you can use to control the flow of a function or statement, allowing you to check for certain conditions while your function progresses.
As an example:
// errors is the flag var
var errors = 0;
for(var i = 0; i < 10; i++)
if(i == 6) // your error condition
errors++;
if(errors) // is the flag "up"? (i.e. > 0)
alert("There was a problem!");
add a comment |
up vote
11
down vote
accepted
up vote
11
down vote
accepted
Flag Variables Defined and Uses says:
A flag variable, in its simplest form, is a variable you define to have one value until some condition is true, in which case you change the variable's value. It is a variable you can use to control the flow of a function or statement, allowing you to check for certain conditions while your function progresses.
As an example:
// errors is the flag var
var errors = 0;
for(var i = 0; i < 10; i++)
if(i == 6) // your error condition
errors++;
if(errors) // is the flag "up"? (i.e. > 0)
alert("There was a problem!");
Flag Variables Defined and Uses says:
A flag variable, in its simplest form, is a variable you define to have one value until some condition is true, in which case you change the variable's value. It is a variable you can use to control the flow of a function or statement, allowing you to check for certain conditions while your function progresses.
As an example:
// errors is the flag var
var errors = 0;
for(var i = 0; i < 10; i++)
if(i == 6) // your error condition
errors++;
if(errors) // is the flag "up"? (i.e. > 0)
alert("There was a problem!");
// errors is the flag var
var errors = 0;
for(var i = 0; i < 10; i++)
if(i == 6) // your error condition
errors++;
if(errors) // is the flag "up"? (i.e. > 0)
alert("There was a problem!");
// errors is the flag var
var errors = 0;
for(var i = 0; i < 10; i++)
if(i == 6) // your error condition
errors++;
if(errors) // is the flag "up"? (i.e. > 0)
alert("There was a problem!");
edited Nov 11 at 0:29
answered Jul 1 '13 at 10:23
Danny Beckett
13.5k1875119
13.5k1875119
add a comment |
add a comment |
up vote
2
down vote
A flag is a variable used to have some value until some condition becomes true,then we change it to false and print the output (Initially flag considered as true)
5
Please expand and give a code example.
– Dementic
Jan 2 '14 at 12:13
add a comment |
up vote
2
down vote
A flag is a variable used to have some value until some condition becomes true,then we change it to false and print the output (Initially flag considered as true)
5
Please expand and give a code example.
– Dementic
Jan 2 '14 at 12:13
add a comment |
up vote
2
down vote
up vote
2
down vote
A flag is a variable used to have some value until some condition becomes true,then we change it to false and print the output (Initially flag considered as true)
A flag is a variable used to have some value until some condition becomes true,then we change it to false and print the output (Initially flag considered as true)
answered Jan 2 '14 at 11:55
sajin
211
211
5
Please expand and give a code example.
– Dementic
Jan 2 '14 at 12:13
add a comment |
5
Please expand and give a code example.
– Dementic
Jan 2 '14 at 12:13
5
5
Please expand and give a code example.
– Dementic
Jan 2 '14 at 12:13
Please expand and give a code example.
– Dementic
Jan 2 '14 at 12:13
add a comment |
up vote
0
down vote
Flag variables are the same for all languages, whether it's RUBY or Python or JavaScript or C++ or even Microsoft® Small Basic™.
A flag variable is usually given two values 0 and 1. So, its used as a Boolean variable where the result toggles between 0 (False) and 1 (True) or as used by the programmer. Some prefer flag=1 and change it to flag=0 in the program to perform an action.
add a comment |
up vote
0
down vote
Flag variables are the same for all languages, whether it's RUBY or Python or JavaScript or C++ or even Microsoft® Small Basic™.
A flag variable is usually given two values 0 and 1. So, its used as a Boolean variable where the result toggles between 0 (False) and 1 (True) or as used by the programmer. Some prefer flag=1 and change it to flag=0 in the program to perform an action.
add a comment |
up vote
0
down vote
up vote
0
down vote
Flag variables are the same for all languages, whether it's RUBY or Python or JavaScript or C++ or even Microsoft® Small Basic™.
A flag variable is usually given two values 0 and 1. So, its used as a Boolean variable where the result toggles between 0 (False) and 1 (True) or as used by the programmer. Some prefer flag=1 and change it to flag=0 in the program to perform an action.
Flag variables are the same for all languages, whether it's RUBY or Python or JavaScript or C++ or even Microsoft® Small Basic™.
A flag variable is usually given two values 0 and 1. So, its used as a Boolean variable where the result toggles between 0 (False) and 1 (True) or as used by the programmer. Some prefer flag=1 and change it to flag=0 in the program to perform an action.
answered Mar 30 at 19:43
Aryan Beezadhur
817
817
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17402125%2fwhat-is-a-flag-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Asked and answered here: stackoverflow.com/questions/1626263/enum-flags-in-javascript
– Bill Gregg
Jul 1 '13 at 10:23
my first hit in google javascriptkit.com/javatutors/valid2.shtml
– Vignesh Vino
Jul 1 '13 at 10:24
look at that example,its pretty confusing!!!
– JETHALAL
Jul 1 '13 at 10:24