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)

Slides:



Advertisements
Similar presentations
Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: Moving On..
Advertisements

1 Pertemuan 14 PHP: Conditions-loops-functions-Array Last Updated: 23 rd May 2011 By M. Arief
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.
1 CS101 Introduction to Computing Lecture 23 Flow Control & Loops (Web Development Lecture 8)
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Control Structures, Operators, and Functions.
Solving One Step Equations and Inequalities Math 7/8.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Chapter 3: Data Types and Operators JavaScript - Introductory.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
Flow of Control Part 1: Selection
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Flow Control. if Almost identical to C
Slide 1 PHP Operators and Control Structures ITWA 133.
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
Class 2Intro to Databases Goals of this class Include & Require in PHP Generating Random Numbers in PHP Arrays – Numerically Indexed and Associative Program.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
CompSci 100E 2.1 Java Basics - Expressions  Literals  A literal is a constant value also called a self-defining term  Possibilities: o Object: null,
4.1 Object Operations operators Dot (. ) and new operate on objects The assignment operator ( = ) Arithmetic operators + - * / % Unary operators.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 03 – Operators, Algorithm Design, Programming Constructs Richard Salomon.
Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Hello world . Variables A variable consists of a name that you can choose, preceded by a dollar ($) sign. Some legal variables.
Rational Expressions relational operators logical operators order of precedence.
 Type Called bool  Bool has only two possible values: True and False.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
© 2016, Mike Murach & Associates, Inc.
Operators and Expressions
Programming for Mobile Technologies
ITM 352 Flow-Control: if and switch
Expressions and Control Flow in JavaScript
String Conversion and Type Juggling
Introduction to MATLAB
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
More about Numerical Computation
Chapter-3 Operators.
Logical Operations In Matlab.
Intro to Programming CURIE 2011.
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Relational Operators.
Chapter 5 Decisions.
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
OPERATORS in C Programming
To Start – 10 Points!! Simplify the following:
Problem 1 Given n, calculate 2n
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
OPERATORS in C Programming
Presentation transcript:

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) + 4) which in PHP would be: $y = 3 * (abs(2*$x) + 4);

Boolian Example 4.1 <?php echo "a: [". (20 > 9). "] "; echo "b: [". (5 == 6). "] "; echo "c: [". (1 == 0). "] "; echo "d: [". (1 == 1). "] "; ?>

Literals and Variables Example 4-3. Five types of literals. " "; // Numeric literal. " "; // String literal. " "; // Constant literal. " "; // Variable string literal. " "; // Variable numeric literal

Expression Statement Example 4-4. An expression and a statement <?php $days_to_new_year = $day_number; // Expression if ($days_to_new_year < 30) { echo "Not long now till new year"; // Statement } ?>

Operators Table 4-1. PHP operator types Operator Description Example Arithmetic Array Assignment Bitwise Basic mathematics Array union Assign values Manipulate bits within bytes $a + $b $a + $b $a = $b ^ 9

PHP operator types Table 4-1. PHP operator types Operator Description Example Arithmetic Array Assignment Bitwise Basic mathematics Array union Assign values Manipulate bits within bytes $a + $b $a + $b $a = $b ^ 9

Operator Precedence If all operators had the same precedence, they would be processed in the order in which they are encountered. In fact, many operators do have the same precedence, so let’s look at a few in Example 4-5. Example 4-5. Three equivalent expressions

Operators PHP’s operators in order of precedence from high to low. Table 4-2. The precedence of PHP operators (high to low)

Operators cont

Associativity

Relational Operators the equality operator is == (two equals signs) Example Assigning a value and testing for equality <?php $month = "March"; if ($month == "March") echo "It's springtime"; ?> Returning either TRUE or FALSE, the equality operator enables you to test for conditions using, for example, an if statement

Comparison operators you can test for more than just equality and inequality. PHP also gives you > (is greater than), = (is greater than or equal to), and <= (is less than or equal to) Example The four comparison operators <?php $a = 2; $b = 3; if ($a > $b) echo "$a is greater than $b "; if ($a "; if ($a >= $b) echo "$a is greater than or equal to $b "; if ($a "; ?>

Logical operators

Conditionals

The if Statement The else Statement The elseif Statement The switch Statement

Conditionals

Conditional Switch Statement

The ? Operator Example Using the ? operator <?php echo $fuel <= 1 ? "Fill tank now" : "There's enough fuel"; ?>

Looping

Loopie do...while Loops for Loops Breaking Out of a Loop The continue Statement

Implicit and Explicit Casting

PHP Dynamic Linking You can split your website up into sensible sections of PHP code, each one self-contained, and therefore treat yourself to a much easier future developing each new feature and maintaining old ones Dynamic Linking in Action Wordpress