How to detect if a variable has changed?

前端 未结 6 1358
生来不讨喜
生来不讨喜 2020-12-10 06:16

I have found myself wanting to do certain things in my programs only if a variable has changed. I have so far been doing something like this:

int x = 1;
in         


        
6条回答
  •  眼角桃花
    2020-12-10 06:47

    Example:

    create a variable with the same name with a number.

    int var1;
    int var2;
    
    if(var1 != var2)
    {
    //do the code here
    
    var2 = var1;
    }
    

    hope this help.

提交回复
热议问题