For循环和if语句 [英] For loop and if statement
本文介绍了For循环和if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for(int intPrjName = 0; intPrjName< [arrPrjName count] ; intPrjName ++)
我在for循环下有一个if / else语句,其中 else
块会显示警告消息。假设数组数为10;那么当 if
失败时, else
块将执行十次,并且警告消息显示十次。我怎样才能停用这个?
解决方案
你的问题是一般的编程问题。最简单的方法就是使用BOOL标志。
BOOL alertShown = NO;
for(int intPrjName = 0; intPrjName< [arrPrjName count]; intPrjName ++){
if(something){
//。 。 。
} else {
if(!alertShown){
[self showAlert:intPrjName]; //或者什么
alertShown = YES;
}
}
}
I am working with the following for loop:
for (int intPrjName = 0; intPrjName < [arrPrjName count]; intPrjName++)
I have a if/else statement under the for loop, in which the else
block shows an alert message. Suppose array count is 10; then when the if
fails, the else
block will execute ten times, and the alert message displays ten times. How can I deactivate this?
解决方案
Your problem is a general programing problem. The simplest way is to just use a BOOL flag.
BOOL alertShown = NO;
for (int intPrjName = 0; intPrjName < [arrPrjName count]; intPrjName++) {
if (something) {
// . . .
} else {
if (!alertShown) {
[self showAlert:intPrjName]; // Or something
alertShown = YES;
}
}
}
这篇关于For循环和if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文