C# study notes–logical statements (branch and loop)
C# study notes–logical statements (branch and loop) Logical statement Conditional branch statement Conditional branch statements can branch the sequentially executed code logic and execute the corresponding code logic when the corresponding conditions are met. IF statement //IF statement block int a=5; if(a>0&&a= 10) { Console.WriteLine(“a3 is greater than or equal to 10”); } else if( a3 > 5 && a3 = 0 && a3 <= 5 ) { Console.WriteLine("a3 is between 0 and 5"); } else { Console.WriteLine("a is less than 0"); } //For beginners, the code logic should be neat and well-proportioned to facilitate comparison of the pairing of nested logic statement blocks. A little exercise in if statements – distinguishing odd and even numbers try { console.writeline(“Please enter an integer”); int num = int.parse(console.readline()); //A number that is divisible by 2 is called an even number if (num % 2 == 0) { console.writeline(“your input is even”); } else { console.writeline(“your input is odd”); } } catch { console.writeline(“Please enter a number”); } Knowledge of statement blocks The logical statement enclosed by {} is a code block. Pay attention to the life cycle of the variables in the code block //Understanding of statement blocks //The life cycle of…