6.3 진입조건 루프 Entry-Condition Loop

공기훈·2021년 9월 7일
0

홍정모의 따배씨

목록 보기
28/49
  • infinte loop
    iteration : 반복하는 것.
	int i;

	i = 1;
	while (i < 5)			// infinite loop
		printf("Hi!\n");	// iteration
	i = 1;
	while (--i < 5)			// wrong direction
		printf("Hi!\n");
  • loop
	i = 1;
	while (i < 5)			
	{
		printf("i before = %d\n", i);
		i++;
		printf("i after = %d\n", i);
	}
i before = 1
i after = 2
i before = 2
i after = 3
i before = 3
i after = 4
i before = 4
i after = 5
	i = 10;
	while (i++ < 5)			// cannot enter
	{
		printf("Hi");
	}

이는 while문 안에 들어가지를 못한다.

i = 0;
	while (i < 3)			
		printf("%i\n", i);
		i++;

이런 경우는 중괄호가 없으므로 0만 계속 출력된다.
indenting.

	i = 0;
	while (i++ < 3);			// null statement
		printf("%i\n", i);

while 문 뒤에 ;이 붙어버려서 조건을 만족시키더라도 printf()를 실행시키지 않는다.

	int i;

	i = 0;
	while (scanf("%d", &i) == 1)
		;// null statement
		// do something (?)        
profile
be a coding master

0개의 댓글