dig1108c lesson 4 fall 2014

13
Intro to Server Side Programming Week Four

Upload: david-laietta

Post on 19-Jun-2015

60 views

Category:

Education


1 download

DESCRIPTION

Valencia College - DIG1108C Lesson 4 Fall 2014

TRANSCRIPT

  • 1. Intro to Server Side ProgrammingWeek Four

2. Basic Git Workflow Review Save and test your work often. If it tests ok, add then commit your work (git add & git commitrespectively) Need to work alone? Work on a branch (git branch & git checkout or gitcheckout -b for short) Done or need to share your work? Send your work to remote (git push) Back to work? Get the latest code (git fetch), then include it (git merge orgit rebase) Need to make a whole project your own? Copy it (git clone), then add itas remote and (git pull) 3. Conditional LogicIf This, Then That 4. Conditional Logic - In computer science, conditional statements,conditional expressions and conditional constructs arefeatures of a programming language which perform differentcomputations or actions depending on whether aprogrammer-specified boolean condition evaluates to true orfalse. Apart from the case of branch predication, this is alwaysachieved by selectively altering the control flow based on somecondition. Computer Science depends heavily on Boolean Algebra forconditional logic. "If this thing is true, then do this. If not, do that." 5. Guarding Expressions Guarding - In computer programming, a guard is a boolean expression that mustevaluate to true if the program execution is to continue in the branch inquestion.Boolean expressions in conditional statements usually also fit this definition ofa guard although they are called conditions.if( ! isset($something) ) $something = 'some value';do_something_with($something);$something = ( isset($something) ? $something : 'default' );$something = do_something_important() or die('error message');use_the_variable($something);$something = do_something_important();if ( $something == false ) die('error message'); 6. Can I go to the Park? Boolean values can be combined with logical operators The order in which conditionals are evaluated matters$permission_from_mom = $mom->request('go_to_park');$permission_from_dad =$dad->request('go_to_park');$permisson_from_both = ($permission_from_mom and $permission_from_dad);$permisson_from_either = ($permission_from_mom or $permission_from_dad);$permisson_from_one = ($permission_from_mom xor $permission_from_dad); 7. Workflow Diagrams & Truth Tables 8. Nested Conditionals Conditionals can also be nested:if ( empty($handedness) ) {if ( test_lefty() and test_righty() )$handedness = 'Ambidextrous';else if ( test_lefty() )$handedness = 'Left Handed';else if ( test_righty() )$handedness = 'Right Handed';else $handedness = 'You Have No Hands!';}echo $handedness; 9. Nested More! Nested conditionals can be written multiple ways:if ( empty($handedness) ) {if ( test_lefty() ) {if( test_righty() )$handedness = 'Ambidextrous';else $handedness = ' Left Handed';}else if ( test_righty() )$handedness = 'Right Handed';else $handedness = 'You Have No Hands!';}echo $handedness; 10. Assignment 4.1Diagramming Conditional Logic 11. Diagramming Logic Partner up and find a project with some if-then-else logic to examine,particularly nested logic Individually, sketch a simple workflow diagram of the logic and assemble a truthtable. Discuss any differences that you may have together when done Collaborate to make one workflow diagram and truth table to show and explainto the class 12. Assignment 4.2Branching Logic in WordPress