본문 바로가기
언어 정리/C# 개념 및 lib

if 문 for 문 while 문

by 알 수 없는 사용자 2024. 1. 8.

 

 


Console.WriteLine("-------------------------------------------------");
Console.WriteLine("if 문 for 문 while 문");

int a = 5;
int b = 3;
int c = 4;

if (a + b > 10)
{
    Console.WriteLine("The answer is greater than 10");
}
else
{
    Console.WriteLine("The answer is not greater than 10");
}

if ((a + b + c > 10) && (a == b))
{
    Console.WriteLine("The answer is greater than 10");
    Console.WriteLine("And the first number is equal to the second");
}
else
{
    Console.WriteLine("The answer is not greater than 10");
    Console.WriteLine("Or the first number is not equal to the second");
}

if ((a + b + c > 10) || (a == b))
{
    Console.WriteLine("The answer is greater than 10");
    Console.WriteLine("Or the first number is equal to the second");
}
else
{
    Console.WriteLine("The answer is not greater than 10");
    Console.WriteLine("And the first number is not equal to the second");
}

int counter = 0;
while (counter < 10)
{
  Console.WriteLine($"while  {counter}");
  counter++;
}

do
{
  Console.WriteLine($"do while {counter}");
  counter++;
} while (counter < 10);


for (int i = 0; i < 10; i++)
{
  Console.WriteLine($"for {i}");
}

for (char column = 'a'; column < 'k'; column++)
{
  Console.WriteLine($"The column is {column}");
}

for (int row = 1; row < 11; row++)
{
  for (char column = 'a'; column < 'k'; column++)
  {
    Console.WriteLine($"The cell is ({row}, {column})");
  }
}


int sum = 0;
for (int number = 1; number < 21; number++)
{
  if (number % 3 == 0)
  {
    sum = sum + number;
  }
}
Console.WriteLine($"The sum is {sum}");

'언어 정리 > C# 개념 및 lib' 카테고리의 다른 글

상속과 다형성  (1) 2024.01.09
생성자  (0) 2024.01.09
var, foreach, List 자료형  (0) 2024.01.08
정수 연산  (1) 2024.01.08
변수 선언 및 문자열 작업  (0) 2024.01.08

댓글