Contexts for If/Loops

Eike Welk eike.welk at gmx.net
Mon Aug 27 19:17:03 UTC 2007


On Thursday 23 August 2007 14:26, Alexander Dymo wrote:
> On 8/23/07, Andreas Pakulat <apaku at gmx.de> wrote:
> > On 23.08.07 03:56:46, Piyush Verma wrote:
> > > Is it valid/usable to have separate contexts for the IF /
> > > while/ For/ try blocks in Python.?
> >
> > No only Python but also C++, so far I don't think this is
> > happening for C++ and I wonder how code-completion works for
> > objects created inside an if-block...
>
> My understanding of contexts was that it is roughly the "{}" block
> in c++ code - the scope where variables are defined. If that's true
> then if/while/for ... should have their own contexts.
>
> But for ruby for example the variable first used inside
> if/while/etc. is still declared/defined after the statement:
>
> if something
>    a = 2
> end
> #here "a" is defined and has either value nil or 2 depending on
> whether something false or true
> puts a
>
> So I wonder whether python has the same rule.

Yes, in Python it works exactly the same:

>>> def test1():
...   if True:
...     a=1
...   print a
...
>>> test1()
1
>>>

Regards,
Eike.




More information about the KDevelop-devel mailing list