music |
OSdata.com |
compound if
summary
This subchapter looks at compound if.
free computer programming text book projecttable of contents
|
music |
OSdata.com |
This subchapter looks at compound if.
free computer programming text book projecttable of contents
|
This subchapter is a stub section. It will be filled in with instructional material later. For now it serves the purpose of a place holder for the order of instruction.
Professors are invited to give feedback on both the proposed contents and the propsed order of this text book. Send commentary to Milo, PO Box 1361, Tustin, California, 92781, USA.
This subchapter looks at compound if.
A compound if is testing more than one condition at once. A compound if can be formed with nested ifs, but sometimes it is more clear to use a compound if (which makes your program easier to maintain for the next few decades). Also, the compound if structure will come up again when creating loops.
The compound if makes use of Boolean logic, in particular the AND and the OR. The following example is not intended to be in any particular programming language, but is valid for Pascal.
IF ( (item1 = TRUE) AND (item2 = TRUE) )
THEN DoSomething();
IF ( (item3 = TRUE) OR (item4 = TRUE) )
THEN DoSomethingElse();
IF ( NOT (item5 = TRUE) )
THEN DoNegateThing();
IF ( NOT (item6 = TRUE) AND (item7 = false) )
THEN DoAnotherThing();
In the example, there is a test to see if both item1 AND item2 are true. The procedure (action) DoSomething is only performed if both item1 and item2 are true. If either is false or if both are false, then the procedure (function/action) DoSomething is skipped.
In the example, there is a test to see if either item3 OR item4 is true. The procedure (action) DoSomethingElse is performed if either item3 and item3 is true. If both are false, then the procedure (function/action) DoSomethingElse is skipped.
The first NOT example simply tests to see if something is NOT true. In this case, we test to see if item5 is true and then take the opposite as our answer. If item5 was true, then we are testing for item5 to not be true and if item5 was false then we are testing for item5 not being false.
The second NOT example is a bit more complicated. There are four parts to this particular condition test. First, we determine if item6 is true. Second, we determine if item7 is false (note that the order of these two tests is not guaranteed in all programming languages). The third step is to do the AND on the two first halves of our test. The final step is to take the opposite of the third step as our final answer. See the chart below:
initial starting position | ||||||||||||
step | item6 | item7 | item6 | item7 | item6 | item7 | item6 | item7 | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | TRUE | TRUE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | ||||
first test (item6 = TRUE) | ||||||||||||
1 | item6 test | item6 test | item6 test | item6 test | ||||||||
1 | TRUE | TRUE | FALSE | FALSE | ||||||||
second test (item7 = FALSE) | ||||||||||||
2 | item7 test | item7 test | item7 test | item7 test | ||||||||
2 | FALSE | TRUE | FALSE | TRUE | ||||||||
third test AND | ||||||||||||
3 | item6 test |
item7 test |
item6 test |
item7 test |
item6 test |
item7 test |
item6 test |
item7 test |
||||
3 | TRUE | FALSE | TRUE | TRUE | FALSE | FALSE | FALSE | TRUE | ||||
3 | AND test | AND test | AND test | AND test | ||||||||
3 | FALSE | TRUE | FALSE | FALSE | ||||||||
final test NOT | ||||||||||||
3 | NOT test | NOT test | NOT test | NOT test | ||||||||
3 | TRUE | FALSE | TRUE | TRUE |
LISP AND(x) LISP function that takes zero or more arguments of type NIL or nonNIL and gives the logical AND.
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
return to table of contents
free downloadable college text book
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
previous page | next page |
Tweets by @osdata |
free computer programming text book projectBuilding a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming. If you like the idea of this project, Supporting the entire project: If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church) free downloadable college text book on computer programming. |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
UNIX used as a generic term unless specifically used as a trademark (such as in the phrase UNIX certified). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2010 Milo
Created: October 31, 2010
Last Updated: November 20, 2010
return to table of contents
free downloadable college text book
previous page | next page |