Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Control Structures, Operators, and Functions.

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 4 Programming In C++, Lecture 3 By Umer Rana.
Advertisements

1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Creating PHP Pages Chapter 7 PHP Decisions Making.
Objectives Using functions to organize PHP code
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
Scripting Languages Perl Chapter #4 Subroutines. Writing your own Functions Functions is a programming language serve tow purposes: –They allow you to.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Slide 1 PHP Operators and Control Structures ITWA 133.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
PHP Constructs Advance Database Management Systems Lab no.3.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
JavaScript, Fourth Edition
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 Chapter 3: Loops and Logic. 2 Control Statements If statement Example NumberCheck.java Relational operators (, >=, ==, !=) Using code blocks with If.
Working with Loops, Conditional Statements, and Arrays.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
PHP (cont.). 2 Functions Definition – function name(arguments){... } –syntax name as for a variable, but without $ arguments as for variables –to return.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP: Moving On..
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Branching statements.
CHAPTER 4 DECISIONS & LOOPS
Arrays An array in PHP is an ordered map
CHAPTER 5 SERVER SIDE SCRIPTING
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Scripts & Functions Scripts and functions are contained in .m-files
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
ITM 352 Flow-Control: Loops
PHP.
Logical Operations In Matlab.
Objectives In this chapter, you will:
PHP an introduction.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Presentation transcript:

Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Control Structures, Operators, and Functions

Open Source Server Side Scripting 2 ECA 236 if statement if ( condition ){ statements; } if ( $dogName == “Halle” ){ echo “You are a Golden Retriever”; }

Open Source Server Side Scripting 3 ECA 236 if / else statements if( condition ){ statement1; } else{ statement2; } if( $dogName = = “Halle” ){ echo “You are a Golden Retriever”; } else{ echo “You are not my dog”; }

Open Source Server Side Scripting 4 ECA 236 if / elseif / else statements if( condition1 ){ statement1; } elseif ( condition2 ){ statement2; } else{ statement3; } if( $dogName = = “Marley” ){ echo “You are a Border Collie”; } elseif( $dogName = = “Halle” ){ echo “You are a Golden Retriever”; } elseif( $dogName = = “Boo” ){ echo “You are a Monster”; } else{ echo “You are not my dog”; }

Open Source Server Side Scripting 5 ECA 236 Nested if statements if( condition1 ){ if( conditionA ){ statementA; } if( conditionB ){ statementB; } } // end outer if else{ statement; }

Open Source Server Side Scripting 6 ECA 236 Comparison Operators SymbolMeaningExample = equal to $x = = $y ! = not equal to $x ! = $y < less than $x < $y > greater than $x > $y < = less than or equal to $x < = $y > = greater than or equal to $x > = $y

Open Source Server Side Scripting 7 ECA 236 Logical Operators SymbolMeaningExample &&and( $x = = $y ) && ( $z > 13 ) | or( $x > $y ) | | ( $z < = 47 ) !not! ( $x < $y )

Open Source Server Side Scripting 8 ECA 236 Operator Precedence OperatorAssociativity ( )N/A [ ]right ! ++ – –right * / %left + –.left < <= N/A == ! =N/A &&left | left ? :left = += – = *= /= %=.=left

Open Source Server Side Scripting 9 ECA 236 switch statements switch ( condition) { case “case 1”: statements; break; case “case 2”: statements; break; case “case 3”: statements; break; default: statements; break; } // end switch

Open Source Server Side Scripting 10 ECA 236 switch example switch ( $dogName ) { case “Marley”: echo “ You are a Border Collie. ”; break; case “Halle”: echo “ You are a Golden Retriever. ”; break; case “Boo”: echo “ You are a Monster. ”; break; default: echo “ You aren’t one of my dogs. ”; break; } // end switch

Open Source Server Side Scripting 11 ECA 236 Embedded PHP <?php if( $dogName == “Marley” ) { ?> You are a Border Collie. <?php } elseif( $dogName == “Halle” ) { ?> You are Golden Retriever. <?php } else { ?> You aren’t one of my dogs. <?php } ?> <?php switch ( $dogName ) { case “Marley”: ?> You are a Border Collie. <?php break; case “Halle”: ?> You are a Golden Retriever. <?php break; default: ?> You aren’t one of my dogs. <?php break; } ?>

Open Source Server Side Scripting 12 ECA 236 while loop while( condition ){ statements; } $counter = 1; while( $counter <= 13 ){ echo “$counter ”; $counter ++; } // end while

Open Source Server Side Scripting 13 ECA 236 for loop for( expression1; condition; expression2 ){ statements; } for( $counter = 1; $counter <= 21; $counter++ ){ echo $counter. ‘, ‘ ; if( $counter % 5 = = 0 ){ echo ‘ ’; } // end if } // end for

Open Source Server Side Scripting 14 ECA 236 do…while loop do statements; while( condition ) $counter = 1; do{ echo “$counter ”; } while( $counter > 13 )

Open Source Server Side Scripting 15 ECA 236 Control Structures  Two other loops are each( ) and foreach( ) which are used with arrays  To stop executing a loop use the break; statement  To stop the execution of an entire PHP script, use the exit; statement

Open Source Server Side Scripting 16 ECA 236 Programmer-defined Functions  Why create functions  reusable code  easier to test and debug  Functions:  define using function keyword  naming follows same rules as variables  names are case-insensitive  can be made to “reply” to the code which called it by returning a value

Open Source Server Side Scripting 17 ECA 236 Programmer-defined Functions cont…  syntax to create a function:  syntax to call a function: function function_name( ) { statements; } function_name( )

Open Source Server Side Scripting 18 ECA 236 Programmer-defined Functions cont…  arguments or parameters  functions can be written to take more than one argument  failure to send correct number of arguments results in an error  use return statement to return a value $x = 3; $y = 4; $z = multiplyThem( $x, $y ); function multiplyThem( $n1, $n2 ) { $product = $n1 * $n2; return $product; }

Open Source Server Side Scripting 19 ECA 236 Programmer-defined Functions cont…  default arguments  setting a default value for an argument makes it optional  passed values overwrite the default  place default arguments last in function definition $x = 3; $z = multiplyThem( $x ); function multiplyThem( $n1, $n2 = 10 ) { $product = $n1 * $n2; return $product; }

Open Source Server Side Scripting 20 ECA 236 Programmer-defined Functions cont…  variable scope  the scope of a variable used in a function is local to the function by default  to create a global variable use global keyword function multiplyThem( $n1, $n2 = 10 ) { global $product; $product = $n1 * $n2; return $product; }