For loop ⇒ n번만큼 반복하라

While loop ⇒ 특정 loop 탈주 컨디션이 충족될 때 까지 반복하라

  1. for loop 처럼 이용하기
#include <stdio.h>
#include <stdlib.h>

int main()
{
		int index = 1;
		while(index <= 5){
				printf("%d\\n", index);
				index++;  // index = index + 1; //
		}
		return 0;
}

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a72b511e-91f4-47a3-a18f-67ac434953ab/Untitled.png

  1. infinite loop
#include <stdio.h>
#include <stdlib.h>

int main()
{
		int index = 1;
		while(index <= 5){
				printf("%d\\n", index); // index++ 를 뺌 //
		}
		return 0;
}

계속 1을 출력함

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f0919b35-9d19-4b56-b0ef-da6fc907cfcb/Untitled.png

  1. Index condition not met

index 값이 while loop의 컨디션과 맞지 않으면, while loop속 명령문은 실행되지 않는다.

#include <stdio.h>
#include <stdlib.h>

int main()
{
		int index = 6;
		while(index <= 5){
				printf("%d\\n", index); // index++ 를 뺌 //
				index++;
		}
		return 0;
}

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/893f6954-585f-4061-9fcf-e87e8665c092/Untitled.png

  1. Do-while loop (index condition not met)