Elseif Statements 
Author Message
 Elseif Statements

Hi. I was just wondering... do all the elseif statements in an if statement
get executed if each one statisfies the condition?

Example:

(Assume all conditions are true before they are passed through the if
statement)

if a = b then
    function 1
elseif b = c then
    function 2
elseif c = d then
    function 3
end if

Will each function get executed or just Function 1?

thanks

Nick



Sat, 21 Jul 2001 03:00:00 GMT  
 Elseif Statements
No.  In your example only function1 executes.  If you re-write the code
without ElseIf, it looks like this:

if a = b then
    function 1
else
    if b = c then
        function 2
    else
        if c = d then
            function 3
        end if
    endif
endif

The other IF statements are nested under the Else clause of the first IF.  
They don't even get evaluated unless the first condition (a = b) is False.

Lee Weiner
weiner AT fuse DOT net

Quote:

>Hi. I was just wondering... do all the elseif statements in an if statement
>get executed if each one statisfies the condition?

>Example:

>(Assume all conditions are true before they are passed through the if
>statement)

>if a = b then
>    function 1
>elseif b = c then
>    function 2
>elseif c = d then
>    function 3
>end if

>Will each function get executed or just Function 1?

>thanks

>Nick



Sat, 21 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. nested if/elseif statements

2. If Then ElseIf Statements

3. Need confirmation about ElseIf statement

4. IF ELSEIF statements in VBScript?

5. if then elseif problem

6. Select case/if then elseif

7. Select Case Vs If - ElseIf

8. If Then ElseIf the solution to this bug?

9. Elseif Condition in Crystal Reports 4.6

10. If-Then-Elseif

11. If..Elseif vs. Select case

12. If..ElseIf..Else problem

 

 
Powered by phpBB® Forum Software