PHP CONDITIONAL STATEMENTS

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
Control Flow Statements: Repetition/Looping
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Creating PHP Pages Chapter 7 PHP Decisions Making.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
true (any other value but zero) false (zero) expression Statement 2
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Visual C++ Programming: Concepts and Projects
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Decisions, Loops, and Arrays Achmad Arwan, S.Kom.
Conditional Control Flow By Muhammad Ahsan Qadar SACS Programming Fundamentals Workshop 1.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
Slide 1 PHP Operators and Control Structures ITWA 133.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
CSI 3125, Preliminaries, page 1 Control Statements.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
 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.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
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 this.
Expressions and Control Flow in PHP
© 2016, Mike Murach & Associates, Inc.
Introduction to C++ Programming Language
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Selection—Making Decisions
Expressions and Control Flow in JavaScript
ITM 352 Flow-Control: Loops
Struktur Control : Decision
Control Structures.
Microsoft Visual Basic 2005 BASICS
Loop Control Structure.
IF if (condition) { Process… }
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Control Structures: Selection Statement
Pages:51-59 Section: Control1 : decisions
Visual Basic – Decision Statements
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Computer Science Core Concepts
Conditional Statements
Conditional Logic Presentation Name Course Name
Conditional statement & LOOPS
Program Flow.
Control Structures: Selection Statement
Pages:51-59 Section: Control1 : decisions
PHP Function and Array 05 CHAPTER Padasalai MOHAMED FAKRUDEEN
LOOPING STRUCTURE Chapter - 7 Padasalai
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Presentation transcript:

PHP CONDITIONAL STATEMENTS Padasalai PHP CONDITIONAL STATEMENTS CHAPTER -6 MOHAMED FAKRUDEEN, PGT-COMPUTER SCIENCE SHAMROCK MATRIC. HR. SEC. SCHOOL. MOGAPPAIR, CHENNAI-107

Learning Objectives To understand the importance of conditional statement To know different type of conditional statements in PHP To know the basic fundamental logic creation using conditional statement

PHP conditional statement Conditional statements are useful for writing decision making logics. It is most important feature of many programming languages , including PHP. They are implemented by the following types: if statement if…else statement if…elseif….else statement switch statement

If statement in PHP If statement executes a statement or a group of statements if a specific condition is satisfied as per the user expectation

SYNTAX: if( condition ) { Execute statement(s) if condition is true; }

Example: <?php $Pass_Mark=35; $Student_Mark=70; if ($Student_Mark>=$Pass_Mark){ echo “The Student is Eligible for the promotion”; }?>

If else statement in PHP If statement executes a statement or a group of statement if a specific condition is satisfied by the user expectation. When the condition gets false (fail) the block is executed.

SYNTAX: If (condition) { Execute statement (s)if condition is true; } Else Execute statement(s) if condition is false;

Example: <?php $Pass_Mark=35; $Student_Mark=70; if($Student_Mark>=$Pass_Mark){ echo “The Student is Eligible for the promotion”; } else{ echo “The Student is not Eligible for the promotion”; }?>

If elseif else statement in PHP: If - elseif- else statement is a combination of if-else statement. More than one statement can execute the condition based on user needs.

SYNTAX If( 1st condition) { Execute statement(s )if condition is true; } elseif( 2nd condition ) Execute statement(s) if 2nd condition is true; Else Execute statement(s) if both conditions are false;

Example: <?php $Pass_Mark=35; $first_class=60; $Student_Mark=70; If($Student_Mark>=$first_class){ echo “The Student is eligible for the promotion with first class”; } elseif ($Student_Mark>=$Pass_Mark){ echo “The Student is eligible for the promotion”; else{ echo “The Student is not eligible for the promotion”; }?>

Switch case: The switch statement is used to perform different actions based on different conditions.

SYNTAX: switch (n) { case label 1: code to be executed if n=label 1; break; case label 2: code to be executed if n=label 2; case label 3: code to be executed if n=label 3; … default: code to be executed if n is different from all labels; }

EXAMPLE: <?php $favcolor = “red” ; switch ($favcolor) { case “red” : echo “Your favorite color is red!” ; break; case “blue” ; echo “Your favorite color is blue!” ; case “green” ; echo “ Your favorite color is green!” ; break ; default: echo “ Your favorite color is neither red , blue, nor green!” ; } ?>

POINTS TO REMEMBER The if statement contains boolean expression inside brackets followed by a single or multi line code block. if –else Statement also provides for a second part to the if statement , that is else. The else statement must follow if or else if statement. else if statement The ‘if’ statement can also follow an “else” statement, if you want to check for another condition in the else part.

NEXT TOPIC: LOOPING STRUCTURE