Iteration Statement - Unity2033/Research GitHub Wiki

  • ν”„λ‘œκ·Έλž¨ λ‚΄μ—μ„œ νŠΉμ •ν•œ μž‘μ—…μ„ 반볡적으둜 μˆ˜ν–‰ν•˜λŠ” λͺ…λ Ήλ¬Έμž…λ‹ˆλ‹€.

Increment & Decrement Operators

  • ν”Όμ—°μ‚°μžλ₯Ό ν•˜λ‚˜μ”© μ¦κ°€μ‹œν‚€κ±°λ‚˜ κ°μ†Œμ‹œν‚¬ λ•Œ μ‚¬μš©ν•˜λŠ” μ—°μ‚°μžμž…λ‹ˆλ‹€.
μ—°μ‚°μž 기호 μ •μ˜
prefix --variable & ++variable λ³€μˆ˜μ˜ 값을 μ¦κ°μ‹œν‚¨ 후에 연산을 μˆ˜ν–‰ν•©λ‹ˆλ‹€.
#include <stdio.h>

void main()
{
   	int protine= 0;
	
	int calorie = ++protine;
	
	printf("The value of the protein variable after pre-increment : %d\n", protine);
	printf("Value of calorie Variable: : %d\n", calorie);
	
	calorie = --protine;
	
	printf("The value of the protein variable after pre-decrement : %d\n", protine);
	printf("Value of calorie Variable: : %d\n", calorie);
}
μ—°μ‚°μž 기호 μ •μ˜
postfix variable-- & variable++ 연산을 μˆ˜ν–‰ν•œ λ‹€μŒ λ³€μˆ˜μ˜ 값을 μ¦κ°μ‹œν‚΅λ‹ˆλ‹€.
#include <stdio.h>

void main()
{
   	int moisture= 0;
	
	int weight = moisture++;
	
	printf("The value of the moisture variable after post-increment : %d\n", moisture);
	printf("Value of weight Variable: : %d\n", weight);
	
	weight = --moisture;
	
	printf("The value of the moisture variable after post-decrement : %d\n", moisture);
	printf("Value of weight Variable: : %d\n", weight);
}

for Statement

  • μ΄ˆκΈ°μ‹μ„ μ—°μ‚°ν•˜μ—¬ μ‘°κ±΄μ‹μ˜ 결과에 따라 νŠΉμ •ν•œ 수만큼 λ°˜λ³΅ν•˜λŠ” λ°˜λ³΅λ¬Έμž…λ‹ˆλ‹€.
#include <stdio.h>

void main()
{
        for(int i = 0; i < 5; i++)
        {
           printf("Process");
        }
}
  • 반볡문이 λ™μž‘λ˜λŠ” μˆœμ„œλŠ” μ΄ˆκΈ°ν™” β†’ 쑰건 검사 β†’ μ‹€ν–‰ β†’ 증감의 ꡬ쑰둜 λ™μž‘ν•©λ‹ˆλ‹€.

while Statement

  • νŠΉμ • 쑰건을 λ§Œμ‘±ν•  λ•ŒκΉŒμ§€ κ³„μ†ν•΄μ„œ μ£Όμ–΄μ§„ λͺ…령문을 μ‹€ν–‰ν•˜λŠ” λ°˜λ³΅λ¬Έμž…λ‹ˆλ‹€.
#include <stdio.h>

void main()
{
        int count = 5;
   
        while(count < 5)
        {
           printf("Execute");

           count--;
        }
}
  • λ°˜λ³΅λ¬Έμ€ 순차적으둜 μ‹€ν–‰ν•˜λ©΄μ„œ 쑰건 λΆ„κΈ°(Branch)λ₯Ό λ§Œλ‚˜κ²Œ 되면, μ–΄λŠ μͺ½μœΌλ‘œ μ‹€ν–‰ 흐름이 κ°ˆμ§€ 미리 예츑(branch prediction)ν•©λ‹ˆλ‹€.

do while Statement

  • 쑰건과 상관없이 ν•œ 번의 μž‘μ—…μ„ μˆ˜ν–‰ν•œ λ‹€μŒ 쑰건에 따라 λͺ…령문을 μ‹€ν–‰ν•˜λŠ” λ°˜λ³΅λ¬Έμž…λ‹ˆλ‹€.
#include <stdio.h>

void main()
{
        int connect = 0;
   
        do
        {
           printf("Access");          
        } while(connect > 3);
}
  • 반볡문의 경우 미리 μ˜ˆμΈ‘ν•΄μ„œ μ‹€ν–‰ν•˜λŠ” ꡬ쑰λ₯Ό κ°€μ§€λ©°, 예츑이 ν‹€λ Έλ‹€λ©΄ ν˜„μž¬ 반볡 λ‚΄μ˜ 쑰건 λΆ„κΈ°λ§Œ λ‹€μ‹œ κ²€μ‚¬ν•˜μ—¬ μ²˜λ¦¬ν•©λ‹ˆλ‹€.
⚠️ **GitHub.com Fallback** ⚠️