programming basics if then else, switch, operators

Post on 31-Oct-2014

26 Views

Category:

Education

8 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

MS Alam TRIVUz

Founder, TRIVUz Network

PF02Programming

Fundamentals

TRIVUz Academy

TRIVUz Academy

Class Id:

Recap PF01

TRIVUz Academy

TRIVUz Academy

We learn before We Define Computer & Program

Define Computer Programming

Programming Process

Programming Language

Inputs & Outputs

Define Logical Processing

Variables

Data TypesProgramming Fundamentals

TRIVUz Academy

www.trivuzacademy.com

We will learn today

Conditional Statement

If… then … else

Switch statement

Operators

Programming Fundamentals

TRIVUz Academywww.trivuzacademy.com

• Conditional statements are the set of command used to perform different actions base on different conditions

• In PHP we have the following conditional statements:• if• if else• else if• switch

Conditional Statement

TRIVUz Academy

If statement

TRIVUz Academy

execute some code only if statement is true

If…

TRIVUz Academy

If…

TRIVUz Academy

if

If…

TRIVUz Academy

if (conditional)

If…

TRIVUz Academy

if (conditional) {

If…

TRIVUz Academy

if (conditional) { // statement to be executed

If…

TRIVUz Academy

if (conditional) { // statement to be executed}

If…

TRIVUz Academy

if ($math < 33) { $result = “Failed!”;}

Example:

If…else statement

TRIVUz Academy

execute some code if statement is true

and some other code if statement is false

If…else…

TRIVUz Academy

if (conditional) { // statement if true}

If…else…

TRIVUz Academy

if (conditional) { // statement if true} else

If…else…

TRIVUz Academy

if (conditional) { // statement if true} else { // statement if false

If…else…

TRIVUz Academy

if (conditional) { // statement if true} else { // statement if false}

If…else…

TRIVUz Academy

if ($math < 33) { $result = “Failed!”;} else { $result = “Passed!”;}

Example:

If…else if…else statement

TRIVUz Academy

execute some code if statement is true

And some other code if statement is false

If…else if…else

TRIVUz Academy

if (conditional) { // statement if true} else if (conditional){ // statement if false and else if true} else { // statement if all false}

If…else if…else

TRIVUz Academy

if (conditional) { // statement if true } else if (conditional){ // whichever matches first } else if (conditional){ // whichever matches first } else if (conditional){ // whichever matches first } else if (conditional){ // whichever matches first } else { // statement if all false}

If…else if…else

TRIVUz Academy

if ($avg > 100) { $grade = "Invalid"; } else if ($avg > 90 and $avg < 100 ) { $grade = "A+"; } else if($avg > 80 and $avg < 90) { $grade = "A"; } else { $grade = "F"; }

Example:

switch statement

TRIVUz Academy

Select one of many block of code to execute

switch

TRIVUz Academy

switch

switch

TRIVUz Academy

switch (value)

switch

TRIVUz Academy

switch (value) {

switch

TRIVUz Academy

switch (value) { case 1: // some code to execute

switch

TRIVUz Academy

switch (value) { case 1: // some code to execute break;

switch

TRIVUz Academy

switch (value) { case 1: // some code to execute break; case 2: // some code to execute break;

switch

TRIVUz Academy

switch (value) { case 1: // some code to execute break; case 2: // some code to execute break; default: // nothing matches, do it

switch

TRIVUz Academy

switch (value) { case 1: // some code to execute break; case 2: // some code to execute break; default: similar to else in if..else

// nothing matches, do it

switch

TRIVUz Academy

switch (value) { case 1: // some code to execute break; case 2: // some code to execute break; default: // nothing matches, do it}

switch

switch (n){case label1:  code to be executed if n=label1;  break;case label2:  code to be executed if n=label2;  break;default:  code to be executed if n is different from both label1 and label2;}

Syntax

TRIVUz Academy

<html><body><?php switch ($x) { case 1:   echo "Number 1";   break; case 2:   echo "Number 2";   break; case 3:   echo "Number 3";   break; default:   echo "No number between 1 and 3"; }?></body></html>

Example

switch

TRIVUz Academy

PHP Operators

TRIVUz Academy

Operators are used to operate on values

Operators

TRIVUz Academy

Arithmetic Operators

Operators

TRIVUz Academy

Assignment Operators

Operators

TRIVUz Academy

Comparison Operators

Operators

TRIVUz Academy

Logical Operators

Thank You

MS Alam TRIVUzFounder, TRIVUz Academytrivuz@gmail.com

top related