의사 결정 구조는 프로그래머가 프로그램에서 평가하거나 테스트할 하나 이상의 조건을 지정해야 하며, 조건이 참인 경우 실행할 명령문과 조건이 참인 경우 실행될 다른 명령문을 선택적으로 지정해야 합니다. 거짓으로 결정되었습니다.
C#의 의사 결정에는 if 문, if-else 문, switch 문 등이 포함됩니다.
C#의 if 문의 예를 살펴보겠습니다.
예시
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int x = 5;
// if statement
if (x < 20) {
/* if condition is true then print the following */
Console.WriteLine("x is less than 20");
}
Console.WriteLine("value of x is : {0}", x);
Console.ReadLine();
}
}
} 출력
x is less than 20 value of x is : 5
C#의 if-else 문의 예를 살펴보겠습니다. 여기서 첫 번째 조건이 거짓이면 else 문의 조건이 확인됩니다.
예시
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int x = 100;
/* check the boolean condition */
if (x < 20) {
/* if condition is true then print the following */
Console.WriteLine("x is less than 20");
} else {
/* if condition is false then print the following */
Cohttps://tpcg.io/HoaKexnsole.WriteLine("x is not less than 20");
}
Console.WriteLine("value of a is : {0}", x);
Console.ReadLine();
}
}
} 출력
x is not less than 20 value of a is : 100