Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the statements of the Java control structure

Shulou Source: shulou.com Published: 2022-05-31 23:51:33 11月13日 Update

This article mainly talks about "what are the sentences of Java control structure". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the sentences of Java control structure.

If structure

If (conditional expression) {/ / execute code} else if (conditional expression) {/ / execute code} else {/ / execute code}

The result of the conditional expression is true | false, which is in the form:

1. Direct Boolean variables

2. Compare the results of operators or the results of logical operators

3. In Java, non-zero numeric types or non-empty strings cannot be used to return Boolean values

Switch structure

Switch (variable name) {case literal constant 1 break;case constant / execute code break;case letter constant 2 break;default:// execute code}

1. The types of variables include integer, char and String types.

2. The literal constant in case should be consistent with the variable type: integer 3, char type'a', String type 'Hello'

3. Break, which is used to jump out of the switch structure; default, which defines the default execution code, which will be executed at the end when there is no break pop-out. In fact, neither break nor default is necessary.

4. When executing the switch statement, compare the value of the variable with the case value one by one. If it matches, the code will be executed from there.

If there is no break statement after the match, the subsequent code will be executed directly instead of the match, and will not jump out of the switch until the breakstatement is encountered or all the code has been executed.

When there is no break in switch, the default statement is executed at the end.

While structure

While (Loop condition) {/ / execute Code}

Do... While structure

Do {/ / execute Code} while (conditional expression)

For cycle structure

For (Loop variable; Loop condition; change Loop variable) {/ / execute Code}

1. The position of the three expressions of loop variable, loop condition and change loop variable cannot be changed, two; the coincidence must be retained, but the loop variable can be written outside the for, and the loop condition and the expression that changes the loop variable can be written internally.

2, loop variables, loop conditions and change loop variables can be more than one expression, the expression and the expression are separated.

Enhanced for cycle

Int [] a = {1 System.out.println (b); {1 System.out.println (b);}; for (System.out.println (b))

At this point, I believe you have a deeper understanding of "what are the sentences of the Java control structure?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Loop code variable structure condition expression statement type control constant result content literal actual Boolean operator learning operation practical deeper Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Docker MariaDB Linux