# Assign instance var in block argument directly

**URL:** <https://forum.crystal-lang.org/t/assign-instance-var-in-block-argument-directly/1457>\
**Category:** Help & Support\
**Created:** [December 7, 2019, 5:34pm UTC](https://forum.crystal-lang.org/t/assign-instance-var-in-block-argument-directly/1457 "2019-12-07T17:34:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bew](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bew/32/113_2.png) [@bew](https://forum.crystal-lang.org/u/bew)\
**Post date:** [December 7, 2019, 5:34pm UTC](https://forum.crystal-lang.org/t/assign-instance-var-in-block-argument-directly/1457/1 "2019-12-07T17:34:46Z")

</div>

Hello (;

While doing the adventofcode day 3, I tried to assign an instance variable from a block argument, which seems to be an invalid syntax:

```auto
    (base_x..target_y).each do |x|
      @current_x = x
      occupied_cells << {@current_x, @current_y}
    end

    # VS

    # expecting block argument name, not INSTANCE_VAR
    # |
    # V
    (base_y..target_y).each do |@current_y|
      # @current_y = y
      occupied_cells << {@current_x, @current_y}
    end

```

Good idea? Maybe we can add it?

* * *

NOTE: I’m not sure where to post a suggestion like this in the forum, I sense that Help & Support is the wrong category for the others doesn’t feel right either… Where should this go?

---

<div class="post-metadata">

**Author:** ![vlazar](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/vlazar/32/31_2.png) [@vlazar](https://forum.crystal-lang.org/u/vlazar)\
**Post date:** [December 8, 2019, 5:06am UTC](https://forum.crystal-lang.org/t/assign-instance-var-in-block-argument-directly/1457/2 "2019-12-08T05:06:11Z")

</div>

Crystal Contrib maybe?
