Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Share Something You Learned Today


  • Please log in to reply
225 replies to this topic

Poll: Poll (21 member(s) have cast votes)

Did you learn anything today?

  1. Voted Yes (19 votes [90.48%])

    Percentage of vote: 90.48%

  2. No (1 votes [4.76%])

    Percentage of vote: 4.76%

  3. I already possess all knowledge. (1 votes [4.76%])

    Percentage of vote: 4.76%

Vote Guests cannot vote

#226 BlueGalaxy

BlueGalaxy

  •  Avatar image
  • Members
  • 155 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:10 AM

Posted 31 May 2018 - 05:07 PM

The ; is straight forward, it always executes command2.

 

But how do you remember the rules for && and ||?

 

We have two commands separated by && or ||, which is OP.

command1 OP command2

These commands joined by the OP form a single big expression, which can either be good or bad.

We want to find out if the final expression is good or bad in as few steps as possible.

 

&& means AND.

good AND good == good

good AND bad   == bad

bad   AND anything  == bad

We are executing the second command only if the first one is good.

command1 && command2

If command1 is good, we then also need to execute command2 to check if that one is good or bad, to determine the final state of the whole expression, which may be either good or bad.

If command1 is bad, bad AND anything is still bad, so we already know that the whole expression is bad, regardless of if command2 is good or not. so we do not need to run command2.

 

 

|| means OR

good OR anything == good

bad   OR good == good

bad   OR bad   == bad

We are executing the second command if the first one is bad.

command1 || command2

If command1 is good, we automatically know that the final big expression is good, so we do not bother to run expression2.

If command1 is bad, then command2 may be either good or bad, so we need to run command2 to find out the end result of the whole big final expression.

 

For more informations see:

https://en.wikipedia.org/wiki/Boolean_algebra


Edited by BlueGalaxy, 31 May 2018 - 05:08 PM.


BC AdBot (Login to Remove)

 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users