Boolean values are either True or False. These are used in logic calculation and expressions--for example, in an "if" or "while" statement. You might set a variable called "isStored" to either True or False indicating whether something has been written to disk or not. Later, when the User tries to close the program, you would test that variable in an "if" statement to determine whether to prompt the User to save the data or not.
// somewhere in the code ...
// ... other code ...
boolean isStored = false;
// ... other code ...
// somewhere else in the code...
void SomeMethod()
{
if (isStored)
{
// ... handle the stored case ...
}
else
{
// ... handle the not-stored case ...
// ... for example, prompt the user to decide whether to save or not ...
}
}
There are other uses for boolean as well.
No comments:
Post a Comment