declaring variables in the loop? (a variable scope question)

If you don't set the value it is undefined basically. Maybe it will be the same, I wouldn't rely on it.

You don't have to use "loop" - just never exit "setup".

Anyway, another approach is to use static, eg.

void loop ()
  {
  static int nomnom = 0;

  nomnom++;  // adds 1 each time
  }

The static variable has local scope but global lifetime, if you see what I mean.

1 Like