在10 games article 2 4
8 science article 2 3
6 sports article 3 2
5 sports article 2 2
3 news article 3 1
循环中调用一次函数后,如何结束函数?例如,在下面的代码中,我希望do...while
只被调用一次,然后在循环中不再被调用。这可能吗?
myfunc()
答案 0 :(得分:1)
要么你可以把它放在do while循环之前
或者您可以保存一个标志变量来存储该函数是否已被执行。
int flag = 0;
do {
if(flag==0){
myfunc();
flag=1;
}
... // Rest of the loop
}
答案 1 :(得分:0)
通常可以使用静态变量来计算第一遍。实施可以取决于它是在通话中还是在回叫中。
static int first = 0;
do{
if(!first){
myfunc();
first = 1;
}
glClear(GL_COLOR_BUFFER_BIT);
// the rest of your code
}while something;
first = 0; //or not zero it if you want to remember the state