亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Multiple nesting of if statements in PHP flow control

Classmate Wang Sixong We told in the first story that he has two secretaries: a life secretary and a work secretary.

Wang Sixong is also extremely well-planned in his travels and projects. He assigned business trips to his life secretary and work secretary respectively:

In life:
Check the weather first, bring rain gear and towel if it rains. Wear sunscreen if it’s not raining
The condition of rain gear, towels and sunscreen should be checked in advance. If not, buy them immediately

At work:
It is necessary to communicate in advance about the work plan before going to Dalian. When ready, it is necessary to check in time, check if it is qualified, and print and sign the form.
If not prepared in time, the main project communication topics should be listed.

Similar to the above situation, we need to use the if...elseif...else repeatedly nested structure.

One or more if statements can be nested in the if statement to realize the judgment of multiple parameters. This is the multiple nesting of if statements. Its structural form is as follows:

<?php
if(判斷1){
    if(判斷2){
            代碼段 1    
    }else{
            代碼段2
        }
}else{
    if(判斷3){
            代碼段3
        }else{
            代碼段4
        }
}
?>

We use a flow chart to express it as follows:
2015-08-08/55c5a2ff40df7

Note:

  1. We are in code segments 1 and 2 , 3 and 4 can be added to the judgment. According to the actual situation, you can also add nesting
  2. Pay attention to the indentation. The function of indentation is only to make the code rich in layering, beautiful and easy to read, and has no impact on the generation of the target code.

We can use codes to express the life requirements of Mr. Wang Sixong in a nested structure. We used a three-level nested structure, and the code is as follows:

<?php
//0表示工作秘書,1表示生活秘書
//用代碼模擬隨機(jī)產(chǎn)生當(dāng)前的工作是生活秘書的還是工作秘書的
$mishu = rand(0,1);

if($mishu){
       //下雨和不下雨的狀態(tài),隨機(jī)產(chǎn)生
       //下雨狀態(tài)為1
       //不下雨狀態(tài)為0
       $xiyu = rand(0,1);
        if($xiyu){
             //是否購買雨傘
             $you = rand(0,1);
             if($you){
                  echo '下雨天,已購買不用買雨傘';
             }else{
                  echo '下雨天,未購買,需要買雨傘';
             }
        }else{
             //是否購買防曬霜
             $you = rand(0,1);
             if($you){
                  echo '沒下雨,有防曬霜';
             }else{
                  echo '沒下雨,需要準(zhǔn)備防曬霜';
             }
        }

}else{
    //是否準(zhǔn)備好了會議議程
    $shifou = rand(0,1);

    if($shifou){
        echo '已準(zhǔn)備好,可以隨時出發(fā)';
    }else{
         echo '沒有準(zhǔn)備好,需要打印,延遲出發(fā)';
    }

}

Warning: For novice programmers, please use caution when using this nested if...else loop. Because too many layers of loops can easily cause problems in the design logic, or there are too few braces, etc., which will lead to inexplicable problems in the program.

I hope you can write it out silently. Also, there cannot be a single grammatical error. In the future, we can use it at any time. If we want to react immediately in the brain, we can start writing.

Continuing Learning
||
<?php //0表示工作秘書,1表示生活秘書 //用代碼模擬隨機(jī)產(chǎn)生當(dāng)前的工作是生活秘書的還是工作秘書的 $mishu = rand(0,1); if($mishu){ //下雨和不下雨的狀態(tài),隨機(jī)產(chǎn)生 //下雨狀態(tài)為1 //不下雨狀態(tài)為0 $xiyu = rand(0,1); if($xiyu){ //是否購買雨傘 $you = rand(0,1); if($you){ echo '下雨天,已購買不用買雨傘'; }else{ echo '下雨天,未已購買,需要買雨傘'; } }else{ //是否購買防曬霜 $you = rand(0,1); if($you){ echo '沒下雨,有防曬霜'; }else{ echo '沒下雨,需要準(zhǔn)備防曬霜'; } } }else{ //是否準(zhǔn)備好了會議議程 $shifou = rand(0,1); if($shifou){ echo '已準(zhǔn)備好,可以隨時出發(fā)'; }else{ echo '沒有準(zhǔn)備好,需要打印,延遲出發(fā)'; } }
submitReset Code