If nesting how to optimize the wording

Source: Internet
Author: User
How do nested if nesting optimize the wording?
If conditions like this can be written again, should not use switch, after all, to determine the time, frequency, IP and other conditions.
If (access time 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 "Error IP Address";
}
}else{
echo "Excessive number of visits";
}
}else{
echo "Error ID range";
}
}
else{
echo "Please take a rest";
}

------to solve the idea----------------------
The parallel notation
while (true) {
If (access time period) {
echo "Normal time period";
}else {
echo "Please take a rest";
Break
}
if (ID range) {
echo "Normal ID range";
}else {
echo "Error ID range";
Break
}
if (number of visits) {
echo "Normal access times";
}else {
echo "Excessive number of visits";
Break
}
if (IP address) {
echo "Normal IP Address";
}else{
echo "Error IP Address";
Break
}
Break
}

------to solve the idea----------------------

$error = 0;
If (access time period) {
echo "Normal time period";
else{
$error = 1;
echo "Please take a rest";
}

if ($error ==0 && ID range) {
echo "Normal ID range";
}else{
$error = 1;
echo "Error ID range";
}

if ($error ==0 && visits) {
echo "Normal access times";
}else{
$error = 1;
echo "Excessive number of visits";
}

if ($error ==0 && IP address) {
echo "Normal IP Address";
}else{
$error = 1;
echo "Error IP Address";
}
  • 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.