control, arrays, and methods of program flow

Source: Internet
Author: User

The main 3 points of the week are program flow control, arrays, and methods

Program flow control is mainly the selection of statements and loop statements: where the SELECT statement is divided into if statement single branch, two branches, multiple branches; If statements can also be nested IF statements this is the nested format of the IF statement:

if (condition 1)

{if (condition 2) {Statement 1}

else{Statement 2}}

else{if (condition 3) {statement 3}

else{Statement 4}, and a switch statement format switch (arithmetic expression) {Case constant expression is Formula 1: statement block 1;break; case constant Expression 2: statement block 2;break; default: statement block; break;} The loop statement constructs the element; the keyword, the code that is executed repeatedly, the loop end condition. Circular statement classification: While loop statement, Do-while Loop statement, for Loop statement. To determine the loop condition position classification: While loop statement, for Loop statement (this is the first verification after loop); The Do-while statement is executed once after validation.

While loop statement format while (Boolean expression) {loop body} Do-whil Loop statement format do{loop body}while (expression); (Note the semicolon is not lost).

The break statement is the control structure used to loop the statement, thus terminating the current loop. The continue statement has the same characteristics as the control structure of the loop statement, which is the function of making the loop immediately transferred to the next iteration.

The FOR Loop statement is a control structure in which we write a specified number of cycles, in the form of a for (variable initialization value; Boolean expression; change of the loop variable) {statement}

The array features are: The array is a contiguous memory space; The elements of the array are variables; the array element subscript (index value) is zero-based, the largest subscript is the length minus one, and each element is initialized after the array is created.
The declaration number format is the data type [] array variable name or the data type array variable name, and then initializes with the keyword new, specifying the array size int []a=new int[0]; Int[] A = {n/a}; (the array initializer does not require the keyword new when creating an array)
Multidimensional arrays: one-dimensional arrays int[] A = new int[1]; Two-dimensional array int[][] b =new int[2][2] ....

A method is a snippet of code that is used to complete a particular function, in the form of an access modifier that can take an optional qualifier return type method name (parameter list) {method body};
Where the access modifier (public) indicates that the definition method is common, can be called in any program, and (static) indicates that the defined method is static and can be used in the Main method; method: The return type can be any data type or object type. A return value that means the type of the value to be returned by the method (void if no return type is used) refers to the result value returned by the method after execution (using the Return keyword End method in the method body to return the concrete result value); We can call it in the program after we define the method. If the method has a return class value (the return type is not a null value) then you can assign the result to a variable, or use the format of the result call in an expression: an object. The method name (argument list) is the parameter that defines the method to accept the Parameter form including (data type, parameter variable name). An argument is a numeric value that is specifically passed into the method when the method is called.

control, arrays, and methods of program flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.