Suppose x and y are distinct identifiers of type integer. show a simple context into which either of the code fragments x = 0; y = 1 or y = 1; x= 0 can be substituted so that in most programming languages the resulting substitutions yield different results. [ February 22, 2006: Message edited by: Sameer Jamal ]
Sameer, is the ':' intentional in "x:= 0"? If so, is it intentional that all 3 other expressions do not include a ':'?
I'm thinking maybe the solution is in a for loop, where
is different in effect from
However we need to distinguish between = and == to get this to compile. Most other languages nowadays distinguish between relational operators and assignments - seeing := makes me think of Pascal for example. I don't see a good way to make your text work for any language I'm currently familiar with. Can you confirm the exact syntax, and maybe give a specific languuage it definitely works in?
"I'm not back." - Bill Harding, Twister
Joined: Feb 16, 2001
Originally posted by Jim Yingst: Sameer, is the ':' intentional in "x:= 0"? If so, is it intentional that all 3 other expressions do not include a ':'?
No it was not intentional it was just a typing mistake. There are few languages where comparison operator '==' will not work for eg: VB 6.0
The context can be
In the case that the first code fragment is substituted for the ellipsis, the effect is to set z to 1, while in the second case z gets set to 0. [ February 22, 2006: Message edited by: Sameer Jamal ]