How to optimize IF nesting?

Source: Internet
Author: User
How to optimize IF nesting? IF conditions like this can be written again, you should not use a switch. after all, you must determine the time, number of times, IP address, and other conditions.
If (access period ){
Echo "normal time period ";
If (ID range ){
Echo "normal ID range ";
If (number of visits ){
Echo "normal access times ";
If (IP address ){
Echo "normal IP address ";
} Else {
Echo "wrong IP address ";
}
} Else {
Echo "too many accesses ";
}
} Else {
Echo "error ID range ";
}
}
Else {
Echo "pay attention to rest ";
}


Reply to discussion (solution)

Parallel writing

While (true) {if (access period) {echo "normal period";} else {echo "note rest"; break;} if (ID range) {echo "normal ID range";} else {echo "error ID range"; break;} if (access count) {echo "normal access count ";} else {echo "too many accesses"; break;} if (IP address) {echo "normal IP address";} else {echo "wrong IP address"; break ;}

$ Error = 0; if (access time period) {echo "normal time period"; else {$ error = 1; echo "pay attention to rest ";} if ($ error = 0 & ID range) {echo "normal ID range";} else {$ error = 1; echo "error ID range ";} if ($ error = 0 & access times) {echo "normal access times" ;}else {$ error = 1; echo "excessive access times ";} if ($ error = 0 & IP address) {echo "normal IP address";} else {$ error = 1; echo "error IP address ";}

The parallel structure on the second floor is easy to understand. the parallel structure on the third floor has never been used ......

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.