Conditionals and Control Flow

Source: Internet
Author: User

Part 1:if and ELSE statements1. Comparisons Operators
    • >Greater than
    • <Less than
    • <=Less than or equal to
    • >=Greater than or equal to
    • ==Equal to
    • !=Not equal to

2. If statements

Now let's see how we can use the comparisons to ask yes or no questions.

Say we want to write a program this asks whether your name is longer than 7 letters. If The answer is yes, we can respond with "you have a long name!" We can do the with an if statement:

<? PHP   $age =n;   if $age > ) {    echo "You can drive!" ;  }? >

An If statement are made if up of the keyword, a condition like we ' ve seen before, and a pair of curly braces . If the answer to the condition is yes, the code inside the curly braces would run.

3. Adding an Else
<? PHP   $name = "Edgar";   if ($name = = "Simon")    {print "I know you!" ;  }   Else {    print "who is?" ;  }? >

Part 2:control flow:switch
1<! DOCTYPE html>234<title></title>56<body>7<?PHP8     Switch(2) {9          Case0:Ten             Echo' The value is 0 '; One              Break; A          Case1: -             Echo' The value is 1 '; -              Break; the          Case2: -             Echo' The value is 2 '; -              Break; -         default: +             Echo"The value isn ' t 0, 1 or 2"; -     } +?> A</body> at

You have both ways of creating a switch. First, there's the made all the past exercises:

Switch ($i) {}

But we can also make it the this to:

Switch ($i):endswitch;

This is called alternative syntax. It exists to provide syntactic sugar

Conditionals and Control Flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.