我在我的C代码中不断遇到以下模式:
_Bool executed = 0;
while (condition) {
executed = 1;
...
}
if (!executed) {
...
}
你有更好的构建方法吗?
理想情况下:
while (condition) {
executed = 1;
...
} else {
...
}
(一个
while
/else
循环,但不具有 Python 的语义。只有在 while 条件立即为 false 时,else
才会执行。)
while
和if
混淆了。 - Barmarif
语句中使用else
,而不能在while
循环中使用。 - Barmar