programming basics if then else, switch, operators

41
MS Alam TRIVUz Founder, TRIVUz Network PF0 2 Programming Fundamentals TRIVUz Academy TRIVUz Academy Class Id:

Upload: trivuz-

Post on 31-Oct-2014

26 views

Category:

Education


8 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Programming Basics if then else, switch, operators

MS Alam TRIVUz

Founder, TRIVUz Network

PF02Programming

Fundamentals

TRIVUz Academy

TRIVUz Academy

Class Id:

Page 2: Programming Basics if then else, switch, operators

Recap PF01

TRIVUz Academy

TRIVUz Academy

Page 3: Programming Basics if then else, switch, operators

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

Page 4: Programming Basics if then else, switch, operators

We will learn today

Conditional Statement

If… then … else

Switch statement

Operators

Programming Fundamentals

TRIVUz Academywww.trivuzacademy.com

Page 5: Programming Basics if then else, switch, operators

• 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

Page 6: Programming Basics if then else, switch, operators

If statement

TRIVUz Academy

execute some code only if statement is true

Page 7: Programming Basics if then else, switch, operators

If…

TRIVUz Academy

Page 8: Programming Basics if then else, switch, operators

If…

TRIVUz Academy

if

Page 9: Programming Basics if then else, switch, operators

If…

TRIVUz Academy

if (conditional)

Page 10: Programming Basics if then else, switch, operators

If…

TRIVUz Academy

if (conditional) {

Page 11: Programming Basics if then else, switch, operators

If…

TRIVUz Academy

if (conditional) { // statement to be executed

Page 12: Programming Basics if then else, switch, operators

If…

TRIVUz Academy

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

Page 13: Programming Basics if then else, switch, operators

If…

TRIVUz Academy

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

Example:

Page 14: Programming Basics if then else, switch, operators

If…else statement

TRIVUz Academy

execute some code if statement is true

and some other code if statement is false

Page 15: Programming Basics if then else, switch, operators

If…else…

TRIVUz Academy

if (conditional) { // statement if true}

Page 16: Programming Basics if then else, switch, operators

If…else…

TRIVUz Academy

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

Page 17: Programming Basics if then else, switch, operators

If…else…

TRIVUz Academy

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

Page 18: Programming Basics if then else, switch, operators

If…else…

TRIVUz Academy

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

Page 19: Programming Basics if then else, switch, operators

If…else…

TRIVUz Academy

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

Example:

Page 20: Programming Basics if then else, switch, operators

If…else if…else statement

TRIVUz Academy

execute some code if statement is true

And some other code if statement is false

Page 21: Programming Basics if then else, switch, operators

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}

Page 22: Programming Basics if then else, switch, operators

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}

Page 23: Programming Basics if then else, switch, operators

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:

Page 24: Programming Basics if then else, switch, operators

switch statement

TRIVUz Academy

Select one of many block of code to execute

Page 25: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

switch

Page 26: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

switch (value)

Page 27: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

switch (value) {

Page 28: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

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

Page 29: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

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

Page 30: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

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

Page 31: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

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

Page 32: Programming Basics if then else, switch, operators

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

Page 33: Programming Basics if then else, switch, operators

switch

TRIVUz Academy

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

Page 34: Programming Basics if then else, switch, operators

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

Page 35: Programming Basics if then else, switch, operators

<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

Page 36: Programming Basics if then else, switch, operators

PHP Operators

TRIVUz Academy

Operators are used to operate on values

Page 37: Programming Basics if then else, switch, operators

Operators

TRIVUz Academy

Arithmetic Operators

Page 38: Programming Basics if then else, switch, operators

Operators

TRIVUz Academy

Assignment Operators

Page 39: Programming Basics if then else, switch, operators

Operators

TRIVUz Academy

Comparison Operators

Page 40: Programming Basics if then else, switch, operators

Operators

TRIVUz Academy

Logical Operators

Page 41: Programming Basics if then else, switch, operators

Thank You

MS Alam TRIVUzFounder, TRIVUz [email protected]