Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
VB
What is the value of m after the following code fragment is executed ?

a=2;
b=2;
c=4;

if(a>b) then
    if(a>c) then
    m=1
else
    m=2
end if
Else
if(c<>0) then
    m=3
else
    m=4
end if
end if
Posted
Updated 27-Jan-14 21:35pm
v3

1 solution

The answer is m = 3.

Start at the top and work your way down. a and b are set to 2. c is set to 4.

Is a is bigger than b (2 bigger than 2)? No. move to the else.

Is c not equal to zero (3 not equal to 0)? Yes. Follow the then.

m is set to 3.

If the code was tabbed a bit differently it might be easier to follow the if/then/else flows.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900