Last active
March 21, 2018 05:13
Star
You must be signed in to star a gist
Toggle between two variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
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
call repeatedly and u get toggled values