Skip to content

Instantly share code, notes, and snippets.

@AcnodeLabs
Last active March 21, 2018 05:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AcnodeLabs/2cada3631cccc079f8ec4c122c120afa to your computer and use it in GitHub Desktop.
Toggle between two variables
int toggleV1(int v1, int v2) {
static short n = 0;
if (n==0) { n=1; return v1;}
if (n==1) { n=0; return v2;}
return 0;
}
int toggleV2(int v1, int v2) {
static bool t = false;
t = !t;
return (t ? v1 : v2);
}
@AcnodeLabs
Copy link
Author

call repeatedly and u get toggled values

@AcnodeLabs
Copy link
Author

V1 can be modified easly to sequence more than 2 values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment