Mysql database
#4

By returning a value in an if statement (and anywhere else in a function really), you:
  1. terminate the function that the if-statement is in (when the if-statement is executed);
  2. can treat everything outside that if statement as the else statement; i.e:
    PHP код:
    someFunction() {
        if(
    someCondition)
            
    // Terminate the function 
            
    return true;
        
    // code under this is ONLY executed when that if statement evaluates to false, thus it can be considered the 'else' statement for that if statement.
        
    return false;

    One could debate that, if the return value in the if statement is the same as the function's end return value, then the else statement should be used:
    PHP код:
    someFunction() {
        if(
    someCondition)
            
    // Terminate the function 
            
    return true;
        
    // code
        
    return true// return value is true which is the same as in the if block

    PHP код:
    someFunction() {
        if(
    someCondition) {
            
    // code 
        
    }
        else {
            
    // code
        
    }
        return 
    true;

I think that's what you meant.
Reply


Messages In This Thread
Mysql database - by PepsiCola23 - 15.11.2016, 15:00
Re: Mysql database - by Pearson - 15.11.2016, 15:12
Re: Mysql database - by PepsiCola23 - 15.11.2016, 20:13
Re: Mysql database - by AndySedeyn - 15.11.2016, 21:16
Re: Mysql database - by AjaxM - 16.11.2016, 05:39

Forum Jump:


Users browsing this thread: 1 Guest(s)