12.25 Daily

01. 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

02: if selection structure
Concept: a grammatical structure that is processed after judgment based on conditions

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

Example:

if (条件一)
{
		条件一成立之后执行的程序
}
else if (条件二)
{
        条件一不成立,条件二成立之后执行的程序
}
else
{
        两个条件都不成立时执行的程序
}

03: switch structure
Concept: used to deal with fixed value branches
Usage:

int a = int.Parse(Console.ReadLine()); / Receive keyboard input and convert to integer

switch(a)
{ case 1: the program executed by /a=1 Console.WriteLine("a=1"); /print output break; case 2: the program executed by /a=2 Console.WriteLine("a=2" ); /Print output break; default: / The program that does not satisfy the execution Console.WriteLine("a is not equal to 1 and 2"); /Print output







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(): basic loop structure
while (condition)
{ program executed in a loop after the condition is established } 1 2 3 4 do{}while(): execute at least once, and then judge the condition do { program that loops at least once } while (condition ) for(): Fill in the brackets with the initial value, loop condition, and condition change for (condition variable: initial value; loop condition; change in condition variable) { program to be executed in a loop after the condition is established } Properties:
















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/zzxin1216/article/details/111714734