$x: true;

@function foobar() {
  @if $x {
    $x: false !global;
    @return foo;
  }
  @else {
    $x: true !global;
    @return bar;
  }
}

div {
  content: foobar();
  content: foobar();
  content: foobar();
  content: foobar();
  $x: false !global;
  content: foobar();
}
