雷竞技电竞平台对话半导体客户支持-同时 https://support.dialog-semiconductor.com/resource-keywords/while 代码检查-避免while循环 https://support.dialog-semiconductor.com/code-review-avoiding-while-loops < div class = "字段field-name-taxonomy-forums field-type-taxonomy-term-reference field-label-above”> < div class = "字段标签" >论坛:,< / div > < div class = "字段条目" > < div class =”field-item甚至“rel = " sioc: has_container " > < a href = " /论坛/ dialog-smartbond-bluetooth-low-energy - % E2 % 80% 93 -软件”“=“sioc:容器sioc:论坛”属性= " rdfs: label skos: prefLabel”数据类型= " " >对话框Smartbond蓝牙低能量-软件< / > < / div > < / div > < / div > < div class =”字段field-name-body field-type-text-with-summary field-label-hidden”> < div class = "字段条目" > < div class =”field-item甚至“财产=“内容:编码”> < p >这不是一个错误,但更多的代码审查的建议。
有许多while循环来迭代cust_prf_funcs数组,就像在prf_utils.c中一样:task_id ! = TASK_NONE) < br / > _ {< br /> _____ 如果(cust_prf_funcs[我]。init_func ! = NULL) < br /> _____ {< br /> _________ cust_prf_funcs (+ +) .init_func (); < br /> _____ }< br /> _____ 其他我+ +,< br / > _} < br / > < /代码> < / p > < p >相同的代码可以写的更漂亮:< / p > < p > <代码> < br / > _ (uint8_t我= 0;cust_prf_funcs[我]。task_id ! = TASK_NONE;I ++) {
_____ if (cust_prf_funcs[I]. php . php . php . php . php . php . php . php . php。init_func ! = NULL) < br /> _____ {< br /> _________ cust_prf_funcs[我].init_func (); < br /> _____ }< br / > _} < br / > < /代码> < / p > < p >循环条件不需要“我& lt;……”!
For循环比while循环更不容易出错。< / p > < / div > < / div > < / div > < div class =”字段field-name-field-forum-keywords field-type-taxonomy-term-reference field-label-above”> < div class = "字段标签" >关键词:,< / div > < div class = "字段条目" > < div class =”field-item甚至“> < a href = " / resource-keywords /而“typeof =“skos:概念”属性=“rdfs: label skos: prefLabel” datatype="">while
Device: 
2016年4月21日星期四08:59:11 +0000 奥伦 3261年https://support.dialog-semiconductor.com https://support.dialog-semiconductor.com/code-review-avoiding-while-loops#comments