2020-12-26

1. Program and program structure

Program concept: a program written by a computer in order to realize a certain function

Sequence structure: execute in the order of the program

Select the structure: judge according to the given conditions, and determine the next step of execution by the result of the judgment

Cyclic structure: within the scope of the conditions, repeated execution

The essence of the condition is ultimately a Boolean value

2: if select structure

Concept: It is a grammatical structure that is processed according to conditions

Usage: When the first condition is not established, the second condition is executed, and the else is not satisfied.

Example:

if (condition 1)
{ program executed after condition 1 is satisfied } else if (condition 2) { program executed after condition 1 is not satisfied, condition 2 is satisfied } else { program executed when neither condition is satisfied }









3: switch structure

Concept: used to deal with fixed value branch
Usage:

int a = int.Parse(Console.ReadLine());     / 接收键盘输入 并转换为整数

switch(a)
{
    
    
	case 1:             / a=1执行的程序
		Console.WriteLine("a=1");            /打印输出
        break;
    case 2:             / a=2执行的程序
        Console.WriteLine("a=2");            /打印输出
        break;
    default:            / 都不满足 执行的程序
        Console.WriteLine("a不等于1和2");     /打印输出
        break;
}

Attributes:

Break: The meaning of breaking will make the code jump out of the entire loop body. C# must add this attribute after each.
Default: When it is not satisfied, execute the program
04: While and for loop structure
concept: within the scope of the establishment of conditions, repeated carried out;

while():基本循环结构
	while (条件)
	{
    
    
		条件成立之后循环执行的程序
	}
do{
    
    }while():至少会执行一次,再判断条件
	do
	{
    
    
	至少循环一次的程序
} while (条件)
for():括号里填 初始值、循环条件、条件变化
	for (条件变量:初始值; 循环条件; 条件变量的变化)
	{
    
    
		条件成立之后循环执行的程序
    }

Attributes:

continue skip this round of loop, the next round will continue to
break out of the entire loop body, the code behind the loop body will be executed

Guess you like

Origin blog.csdn.net/weixin_51734251/article/details/111737267