영어로 읽는 코딩

23 [C] for와 while

while & for

 

Whether to use while or for is largely a matter of personal preference. For example, in

 

while ((c = getchar()) == ' ' || c == ’ \n' || c == '\t')

           ;             /* skip white space characters */

 

there is no initialization or re-initialization, so the while is most natural. The for is preferable when there is a simple initialization and increment, since it keeps the loop control statements close together and visible at the top of the loop. This is most obvious in

 

for (i = 0; i < n; i++)
   

 

 

 

 

[The C Programming Language p.60-61]

댓글

댓글 본문
버전 관리
Yoo Moon Il
현재 버전
선택 버전
graphittie 자세히 보기