Answer the question
In order to leave comments, you need to log in
How to learn to quickly count logical expressions?
As a programmer, I often come across logical expressions. As soon as you need to write something like A || B & (C || D) , I start to calculate for a long time what will happen at the output. How to learn to solve such problems as efficiently as possible?
Answer the question
In order to leave comments, you need to log in
Break the complex into simple parts. A || B & (C || D) come up with a more practical example (equivalent to yours).
if (!file.exist || (file.type != DIRECTORY) & (file.creationDate < lastGoodDate || file.size > maxSize))
{
printErrorMessage();
}
bool isBadFile(file)
{
if (!file.exist)
return true;
if (file.type == DIRECTORY)
return fasle; //skip directories
bool isTooOld = file.creationDate < lastGoodDate;
bool isTooBig = file.size > maxSize;
return isTooBig || isTooOld
}
if (isBadFile(file))
{
printErrorMessage();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question