Take a look at this PHP code

Source: Internet
Author: User
This code, when entering the first if, will judge $ch+ $en + $ma >220, but $ch+ $en + $ma <220, the event stream will not jump out of this if, execute the later else?


  
   60&&$ma>60&&$en>60){    if($ch+$en+$ma>220)    {$tg='合格';};}else{$tg='不合格';}?>

Reply content:

This code, when entering the first if, will judge $ch+ $en + $ma >220, but $ch+ $en + $ma <220, the event stream will not jump out of this if, execute the later else?


  
   60&&$ma>60&&$en>60){    if($ch+$en+$ma>220)    {$tg='合格';};}else{$tg='不合格';}?>

1. The if...else between the same team is based on whether the conditions in the if are satisfied with the jump, different will not, even if the nested. So when a nested if condition in your if is not satisfied, it will look for any else that has it paired, and I'm sorry, there is no else associated with it, so $tag will be empty.
2. Note The writing format, the readability of the code, indentation, the position of the curly brace is immediately after the judgment condition, the operator must have a space on both sides.


  
    60 && $ma > 60 && $en>60){    if($ch + $en+ $ma > 220){        $tg = '合格';    }else{        $tg = '不合格';    }}else{    $tg = '不合格';}?>

Of course, Xiayongsheng's style is more concise, but slightly more readable.

The next else is the first if Judge 60, if there is no else, that is, TG is empty
You can modify the following


  
   = 220 && $ch >= 60 && $ma >= 60 && $en >= 60;$tg = $condition ? '及格' : '不及格';?>

if(明天下雨){   // 伞或雨衣   if(骑车) {      // 雨衣   } } else {   // 不带}

The rain is the premise of the raincoat.

If and else are paired (but else not required).
If at the outermost level corresponds to the outermost else, and so on.

  • 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.