Given a variable x, initially x = 0, find the value of x after the statement: if 6 + 6 = 12 then x := x + 1. Note: ":=" means assignment
Isnt it 1
why?
Since 6+6=12 is a TRUE statement x=0+1=1
?
If 6+6=12 then x=x+1 ^ THIS STATEMENT IS TRUE so, x=0+1
why x = 0 + 1?
because the initial value of x is 0
so it's just substitution?
Yes.......... x will be initial value of x +1
then what's the purpose of 6 + 6 = 12?
Its the given condition........ we do x=x+1 only if the given condition is TRUE
what if it's false?
The value of x will not increase by 1
That means we wont do x=x+1
so what will be done?
nothing as nothing said to be done if the condition is FALSE
like x will not be incremented, it will remain 0. u learning programming?
couldn't x be any value because according to conditional statement.. if p is false then p->q is true for any truth value of q
isn't this related to conditional statements?
and @hartnn since it's in the math section...this is just discrete mathematics
Join our real-time social learning platform and learn together with your friends!