Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:04:18+00:00 2026-06-09T05:04:18+00:00

What control structures can one use instead of multiple nested IF statements. eg: function

  • 0

What control structures can one use instead of multiple nested IF statements.

eg:

function change_password($email, $password, $new_password, $confirm_new_password)
{
    if($email && $password && $new_password && $confirm_new_password)
    {
        if($new_password == $confirm_new_password)
        {
            if(login($email, $password))
            {
                if(set_password($email, $new_password))
                {
                    return TRUE;
                }
            }
        }
    }
}       

This function is used like this:

if(!change_password($email, $password, $new_password, $confirm_new_password)
{
    echo 'The form was not filled in correctly!';
    exit;
}

I call all my functions like this, and I’m wondering if there’s something wrong with my coding style. I’m having my doubts because if I follow this design then that means every single function I write will just be with nested with IF’s, checking if there are errors at every stage. Is this what other people do?

I don’t see many other scripts written like this, with the nested IF’s making a triangle shape and only having the desired result in the very middle. If the middle isn’t reached, then something screwed up.

Is this a good function structure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:04:21+00:00Added an answer on June 9, 2026 at 5:04 am

    Nesting too deeply is generally a bad idea – it’s spaghetti logic and difficult to follow. Since each of your verification steps depends on the previous stage having succeeded, don’t nest at all – just bail out when a stage fails:

    function change_password(blah blah blah) {
       if (!$condition1) {
          return false;
       }
       if (!$condition2) {
          return false;
       }
       etc....
    
    
       // got here, must have succeeded
       return true;
    }
    

    That makes it explicitly clear what the logic sequence is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On the MSVC++ compiler, one can use the __int8 , __int16 , __int32 and
Is there any, official or unofficial , documentation for control structures like this one:
If a language has control structures and variables, but no support for arrays, lists,
Is it possible to use continue/break in a %control structure loop. For example: %
I am f...fed up with Subversion. Need a version control that: Can be used
I have a User control (because I use the same in other page, so
I'm developing a library which you can use in client or server code. More
I'm getting a json from server. I can parse only one JSON at time.
The example below is an extráct from http://php.net/manual/de/control-structures.switch.php <?php $totaltime = 0; switch ($totaltime)
Structured programming languages typically have a few control structures, like while , if ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.