Control Structures. The if Conditional Condition must go within parentheses Statements come after the curly brace Example: if (empty ($name)) { print.

Slides:



Advertisements
Similar presentations
Which star sign is it? What are its: Strengths? Weaknesses? What star signs are your perfect partner?
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Personality Characteristics of Zodiac Signs
Weather Forecasting Assignment For more information please see the links under today’s date on our class webpage.
Chubaka Producciones Presenta :.
2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
P Pathophysiology Calendar. SundayMondayTuesdayWednesdayThursdayFridaySaturday January 2012.
Horoscope activity Prepared and contributed by Nancy Power.
Activity 1: Click on the pictures and repeat the zodiacs. ARIES March 21 – April 20 TAURUS April 21 – May 20 GEMINI May 21 – June 21 CANCER June 22.
Preview p.96 NB p. 95 “Research Methods” Title Page Complete the Fact or Falsehood Activity.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.
Horoscopes. Sun signs There are twelve sun signs.
Play the game Game Directions Story Credits Copyright Notice Game Preparation Objectives Game Pieces.
Aquarius, The Water Bearer January 21-February 19 If you were born under the sign of Aquarius, you are sociable and idealistic.
Mikale Thomas CSI 1020 #126 Fall 2010  Aquarius - January 21 - February 19 Aquarius  Pisces - February 20- March 20 Pisces  Aries - March 21 -
WE ARE WIZARDS, AREN'T WE?.
Does your zodiac sign determine how successful you will be? Fortune magazine collected the zodiac signs of 256 heads of the largest 400 companies. Is there.
Retrograde Motion You’re going the wrong way!. History of Retrograde Motion Ancient Greeks noticed that certain celestial objects changed their locations.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
2007 Monthly Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.

You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
Using Arrays in PHP (Part I) Lecture # 6. What is an array? It is a collection of multiple values assembled into one variable An array can consist of.
By: max. Cancer is a sickness as well a horoscope.
Horoscopes and Birthdays When’s your birthday?When’s your birthday? My birthday is on November 2nd, 1980.My birthday is on November 2nd, What’s your.
Constellations - Astrology - Horoscopes - the Zodiac Since the dawn of history, man has studied the sky. The sun was the brightest object that man saw.
Star signs Star signs! What's your star sign?.
Observing the Constellations of the Zodiac (Ecliptic Plane)
Horoscope Sign English
Capricornus (Cpr) the goat Earth’s position in orbit: July 21 The Sun appears here: January 21.
Constellations The constellations are totally imaginary things that poets, farmers and astronomers have made up over the past 6,000 years (and probably.
It’s in the Stars Western Astrology. Pre-Reading Activity Pre-Reading Activity Post-Reading ActivityPost-Reading Activity.
READING ACTIVITY ZODIAC.
Chapter 11 Chi Square Distribution and goodness of fit.
August 25, 2015 Please pick up a syllabus, a green worksheet, and a pink slip. Goal: Compare science and pseudoscience.
Research Methods in Psychology Experimental Research –The only research method that can be used to determine cause and effect –Often called the experimental.
WORD JUMBLE. Months of the year Word in jumbled form e r r f b u y a Word in jumbled form e r r f b u y a february Click for the answer Next Question.
DATE POWER 2 INCOME JANUARY 100member X 25.00P2, FEBRUARY 200member X 25.00P5, MARCH 400member X 25.00P10, APRIL 800member.
The Zodiac By Ryan. Names of the Zodiac This is the zodiac. The names are Aries, Taurus, Gemini, Cancer, Leo, Virgo, Libra, Scorpio, Sagittarius, Capricorn,
 Profile P.2  Good friendship matches P.3  History & Mythology P.4+5  team.5.
Introduction to Astronomy Astronomy vs Astrology Created by Joshua Toebbe NOHS 2015.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
3 – Ignite Movement Outward 4 – Anchor Movement Inward 5 – Spin Movement Spirals.
Бёрн Джонс Вифлеемская звезда ARIES (March 21-April 19) THE RAM – the first sign of zodiac. ARIES are brave, firm ( stable), intellectual,
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
Today’s Lesson Learn new vocabulary for describing personalities Look at how Americans & Koreans learn about someone’s personality.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Astrology.
Star Signs Months Ordinal Numbers Dates.
Months of the Year ©Copyright
Dictation practice 2nd Form Ms. Micaela-Ms. Verónica.
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
2017/18 Payment Calendar Due Date Cut-off Day 1st of every month
The SAT will be given at ECHS on the dates below!
McDonald’s Kalender 2009.
2300 (11PM) September 21 Blue line is meridian..
What is Your Horoscope? How many know your sign? How many of you read your horoscopes? This all comes from an area of study called astrology. Astrology.
Horoscope activity Prepared and contributed by Nancy Power.
McDonald’s calendar 2007.
Visual English You understand English can eyes ! your with.
Teacher name August phone: Enter text here.
MONTHS OF THE YEAR January February April March June May July August
McDonald’s calendar 2007.
Habitat Changes and Fish Migration
2015 January February March April May June July August September
Habitat Changes and Fish Migration
Presentation transcript:

Control Structures

The if Conditional Condition must go within parentheses Statements come after the curly brace Example: if (empty ($name)) { print ‘ please enter a name. ’ }

Form

Code Example for the if Conditional 6.2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Registration <?php // Script handle_reg.php // Address error handing. ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // In case register_globals is disabled. $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $ = $_POST[' ']; $password = $_POST['password']; $confirm = $_POST['confirm']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $color = $_POST['color']; print ' Registration Results: '; // Validate the first name. if (empty ($first_name)) {

print ' Please enter your first name. '; } // Validate the last name. if (empty ($last_name)) { print ' Please enter your last name. '; } // Validate the address. if (empty ($ )) { print ' Please enter your address. '; } // Validate the password. if (empty ($password)) { print ' Please enter your password. '; } ?>

Using else 6.3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Registration <?php // Script handle_reg.php - second version after Script 6.2 // Address error handing. ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // In case register_globals is disabled. $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $ = $_POST[' ']; $password = $_POST['password']; $confirm = $_POST['confirm']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $color = $_POST['color']; print ' Registration Results: '; // Validate the first name. if (empty ($first_name)) { print ' Please enter your first name. '; }

// Validate the last name. if (empty ($last_name)) { print ' Please enter your last name. '; } // Validate the address. if (empty ($ )) { print ' Please enter your address. '; } // Validate the password. if (empty ($password)) { print ' Please enter your password. '; } // Validate the month. if (is_numeric ($month)) { $birthdate = $month. '-'; } else { print ' Please select the month you were born. '; } // Validate the day. if (is_numeric ($day)) { $birthdate.= $day. '-'; } else { print ' Please select the day you were born. '; } // Validate the year. if (is_numeric ($year)) { $birthdate.= $year; } else { print ' Please enter the year you were born as four digits. '; } print "You entered your birthday as $birthdate"; ?>

PHP Operators OperatorUsageType ==EqualityComparison !=InequalityComparison AND/&&Andlogical OR/l lOrlogical.Concatenationstring.=Concatenates to the values of a variable Concatenation and assignment

Example on operators 6.4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Registration <?php // Script handle_reg.php - third version after Scripts 6.2 and 6.3 // Address error handing. ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // In case register_globals is disabled. $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $ = $_POST[' ']; $password = $_POST['password']; $confirm = $_POST['confirm']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $color = $_POST['color']; print ' Registration Results: '; // Validate the first name. if (empty ($first_name)) { print ' Please enter your first name. '; }

// Validate the last name. if (empty ($last_name)) { print ' Please enter your last name. '; } // Validate the address. if (empty ($ )) { print ' Please enter your address. '; } // Validate the password. if (empty ($password)) { print ' Please enter your password. '; } // Check the two passwords for equality. if ( $password != $confirm ) { print ' Your confirmed password does not match the original password. '; } // Validate the month. if (is_numeric ($month)) { $birthdate = $month. '-'; } else { print ' Please select the month you were born. '; } // Validate the day. if (is_numeric ($day)) { $birthdate.= $day. '-'; } else { print ' Please select the day you were born. '; } // Validate the year. if (is_numeric ($year)) { $birthdate.= $year; } else { print ' Please enter the year you were born as four digits. '; } // Check that they were born before if ($year >= 2004) { print ' Either you entered your birth year wrong or you come from the future! '; } print "You entered your birthday as $birthdate"; ?>

Using elseif 6.6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Registration <?php // Script handle_reg.php - fifth version after Scripts 6.2, 6.3, 6.4 and 6.5 // Address error handing. ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // In case register_globals is disabled. $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $ = $_POST[' ']; $password = $_POST['password']; $confirm = $_POST['confirm']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $color = $_POST['color']; print ' Registration Results: '; // Validate the first name. if (empty ($first_name)) { print ' Please enter your first name. '; } // Validate the last name. if (empty ($last_name)) { print ' Please enter your last name. '; } // Validate the address. if (empty ($ )) { print ' Please enter your address. '; }

// Validate the password. if (empty ($password)) { print ' Please enter your password. '; } // Check the two passwords for equality. if ($password != $confirm) { print ' Your confirmed password does not match the original password. '; } // Validate the month. if (is_numeric ($month)) { $birthdate = $month. '-'; } else { print ' Please select the month you were born. '; } // Validate the day. if (is_numeric ($day)) { $birthdate.= $day. '-'; } else { print ' Please select the day you were born. '; } // Validate the year. if ( is_numeric ($year) AND strlen ($year) == 4 ) { // Check that they were born before if ($year >= 2004) { print ' Either you entered your birth year wrong or you come from the future! '; } else { $birthdate.= $year; } // End of 2nd conditional. } else { // Else for 1st conditional. print ' Please enter the year you were born as four digits. '; } // End of 1st conditional. // Validate the color. if (!$color) { print ' Please select your favorite color. '; }

print "You entered your birthday as $birthdate"; // Get the horoscope sign. if ($month == 1) { // January if ($day <= 19) { $sign = 'Capricorn'; } else { $sign = 'Aquarius'; } } elseif ($month == 2) { // February if ($day <= 18) { $sign = 'Aquarius'; } else { $sign = 'Pisces'; } } elseif ($month == 3) { if ($day <= 20) { $sign = 'Pisces'; } else { $sign = 'Aries'; } } elseif ($month == 4) { if ($day <= 19) { $sign = 'Aries'; } else { $sign = 'Taurus'; } } elseif ($month == 5) { if ($day <= 20) { $sign = 'Taurus'; } else { $sign = 'Gemini'; } } elseif ($month == 6) { if ($day <= 19) { $sign = 'Gemini';

} else { $sign = 'Cancer'; } } elseif ($month == 7) { if ($day <= 22) { $sign = 'Cancer'; } else { $sign = 'Leo'; } } elseif ($month == 8) { if ($day <= 22) { $sign = 'Leo'; } else { $sign = 'Virgo'; } } elseif ($month == 9) { if ($day <= 22) { $sign = 'Virgo'; } else { $sign = 'Libra'; } } elseif ($month == 10) { if ($day <= 22) { $sign = 'Libra'; } else { $sign = 'Scorpio'; } } elseif ($month == 11) { if ($day <= 21) { $sign = 'Scorpio'; } else { $sign = 'Sagittarius'; } } elseif ($month == 12) { if ($day <= 21) { $sign = 'Sagittarius'; } else { $sign = 'Capricorn'; } print " You are a(n) $sign. "; ?>

The Switch Conditional The switch conditional takes only one possible condition which is the value of a variable. Example: switch ($variable) { case “value”: statements; break; }

Switch Code Example 6.7 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Registration <?php // Script handle_reg.php - sixth version after Scripts 6.2, 6.3, 6.4, 6.5 and 6.6 // Address error handing. ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // In case register_globals is disabled. $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $ = $_POST[' ']; $password = $_POST['password']; $confirm = $_POST['confirm']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $color = $_POST['color']; print ' Registration Results: '; // Validate the first name. if (empty ($first_name)) { print ' Please enter your first name. '; } // Validate the last name. if (empty ($last_name)) { print ' Please enter your last name. '; } // Validate the address. if (empty ($ )) { print ' Please enter your address. '; }

// Validate the password. if (empty ($password)) { print ' Please enter your password. '; } // Check the two passwords for equality. if ($password != $confirm) { print ' Your confirmed password does not match the original password. '; } // Validate the month. if (is_numeric ($month)) { $birthdate = $month. '-'; } else { print ' Please select the month you were born. '; } // Validate the day. if (is_numeric ($day)) { $birthdate.= $day. '-'; } else { print ' Please select the day you were born. '; } // Validate the year. if ( is_numeric ($year) AND strlen ($year) == 4 ) { // Check that they were born before if ($year >= 2004) { print ' Either you entered your birth year wrong or you come from the future! '; } else { $birthdate.= $year; } // End of 2nd conditional. } else { // Else for 1st conditional. print ' Please enter the year you were born as four digits. '; } // End of 1st conditional. // Validate the color. if (!$color) {

print ' Please select your favorite color. '; } print "You entered your birthday as $birthdate"; // Get the horoscope sign. switch ($month) { case 1: if ($day <= 19) { $sign = 'Capricorn'; } else { $sign = 'Aquarius'; } break; case 2: if ($day <= 18) { $sign = 'Aquarius'; } else { $sign = 'Pisces'; } break; case 3: if ($day <= 20) { $sign = 'Pisces'; } else { $sign = 'Aries'; } break; case 4: if ($day <= 19) { $sign = 'Aries'; } else { $sign = 'Taurus'; } break; case 5: if ($day <= 20) { $sign = 'Taurus'; } else { $sign = 'Gemini'; } break; case 6: if ($day <= 19) { $sign = 'Gemini'; } else { $sign = 'Cancer';

} break; case 7: if ($day <= 22) { $sign = 'Cancer'; } else { $sign = 'Leo'; } break; case 8: if ($day <= 22) { $sign = 'Leo'; } else { $sign = 'Virgo'; } break; case 9: if ($day <= 22) { $sign = 'Virgo'; } else { $sign = 'Libra'; } break; case 10: if ($day <= 22) { $sign = 'Libra'; } else { $sign = 'Scorpio'; } break; case 11: if ($day <= 21) { $sign = 'Scorpio'; } else { $sign = 'Sagittarius'; } break; case 12: if ($day <= 21) { $sign = 'Sagittarius'; } else { $sign = 'Capricorn'; } break; } // End of switch. print " You are a(n) $sign. "; ?>

The for Loop PHP supports three kinds of loops: for: performs specific statements for a determined number of iterations. while: runs until a condition is false foreach: commonly used with arrays

Code Example 6.8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Register Please complete this form to register: First Name: Last Name: Address: Password: Confirm Password: Date Of Birth: Month January February March April May June July August September October November December Day <?php

// Print out 31 days. for ($d = 1; $d <= 31; $d++) { print " $d \n"; } ?> Favorite Color: Pick One Red Yellow Green Blue