Hello, On Monday, February 8, 2016 at 1:32:26 PM UTC+1, FQ wrote: > > did you mean to write 'i==2' instead of 'x==2' in the second if statement? > > Yep, sorry. Typo.
On Monday, February 8, 2016 at 12:58:04 PM UTC+1, [email protected] wrote: > > The x is not kept between iterations of the for see > http://docs.julialang.org/en/release-0.4/manual/variables-and-scoping/#for-loops-and-comprehensions > That explains this behaviour, indeed. Thanks, ---david > Am 08.02.2016 um 12:41 schrieb David van Leeuwen: > > Hello, > > > > According > > to > http://docs.julialang.org/en/release-0.4/manual/control-flow/#man-conditional-evaluation > > variables > > in if blocks do not introduce lexical scope, and hence are available > > afterwards. This makes sense and is what I need. > > > > However, it seems afterwards relates to position in the encapsulating > > block, and not to execution time. > > > > | > > functiontestif() > > | > > for i in 1:2 > > if i==1 > > x = 0 > > end > > if x==2 > > println(x) > > end > > end > > end > > > > > > This code gives me an undefined `x` in the print statement, where I > > would have expected `x` to be initialized in the first iteration. It > > seems I need to define `x` outside the for loop, even though I don't > > need it there. > > > > Is this interpretation in Julia intentional? > > > > Cheers, > > > > ---david > > > >
