如果在 if 条件下声明,如何将 C 三元语句转换为 if/else?

How to convert a C ternary statement into an if/else if declared within an if condition?

于是翻遍了海量的互联网,也没能找到这个问题的答案。

假设我有这段代码:

if(P4IN & GPIO_PIN1?0:1){
        if (state==1){
            state = 0;
            //Wait for this state to pass -- ends up saving the current state on button press.
            while (counter < 10000){
                counter++;
            }
        }
        else{
            state = 1;
            while (counter < 10000){
                counter++;
            }
        }
    }

我要如何重写才能使 if(P4IN & GPIO_PIN1?0:1) 不这样写。我不介意创建额外的 if/else 条件或扩展此代码块(用于 MSP432)

感谢您的宝贵时间。

你可以将整个事情简化为:

if (!(P4IN & GPIO_PIN1)) {
  state = !state;

  while (counter < 10000) {
    counter++;
  }
}