English Version of Java Study - Lesson 1

本文深入探讨了Java中的流程控制结构,包括顺序结构、选择结构和循环结构的使用方法及语法格式。详细介绍了单分支、双分支和多分支选择结构,并讲解了switch语句的执行步骤,帮助读者掌握Java编程的基础。

I. Process Control - Selection Structure

 A. Process Control Structure

  1. Introduction to the process signs

    Process begins / ends       Judge and branch

 

    Calculation procedure.     Connection

 

    Input / output instructions        Process line

  2. Introduction of Process Control Structure

 

 

    Sequence          Selection              Loop

    a. Sequential structure: Sequential structure refers to the structure in which the program      executes each statement in turn from top to bottom without any judgment or jumping.      The preceding examples all adopt sequential structure.

    b. Choose structure: Choose structure to execute different code according to the result of      condition judgment. The selected structure can be subdivided into single-branch      structure, double-branch structure and multi-branch structure. Java provides if control      statements and switch statements to implement the selection structure.

    c. Loop structure: Loop structure is to execute a piece of code repeatedly according to      the judgment condition. Java provides while statement, DO-WHILE statement, for      statement to implement loop structure.

 B. Selection Structure

  1. "If"

   a. There are three different kinds of "If" control statement. 

    - Single branch structure 

    - Double branch structure

    - Muti-molecular structure

   b. Using "If" for single branch structure

    - Format: 

      

   c. Steps of Judge the result of the expression:

    - Judge the expressed results.

    - Execute the statement if the result of the expression is true.

    - If the result of the expression is false, skip the statement.

  2. "If-else"

   a. Format:

     

   b. Steps of Judge the result of the expression:

    - Judge the result of the expression

    - If the result of the expression is true, execute statement 1

    - If the result of the expression is false, execute statement 2

  3. Using multi-branch if statement to realize multi-branch processing

   a. The grammatical format of the multi-branch if statement:

      

   b. The execution steps of the multi-branch if statement:

    - The result of expression 1 is judged.

    - If the result of expression 1 is true, statement 1 is executed; otherwise expression 2 is judged.

    - If the result of expression 2 is true, statement 2 is executed; otherwise statement 3 is executed.

 C. "Switch"

  1. Format: 

   

  2. The execution steps of the switch statement:

   - Calculate the value of the expression after switch

   - Comparing the calculated results from top to bottom with the constant values after case

   - If equal, the code block after the constant is executed and the break statement ends.

   - If the constants after any case do not match, execute the statement in default

NOTE:

01. If you need to jump out after each case is executed, don't forget to write a break after each case.

02. Constants after case cannot be the same

03. The order of default blocks can be changed, but attention should be paid to their execution order. Normally, default blocks are placed at the end, or they can be omitted.

转载于:https://www.cnblogs.com/study-java-with-english-syq/p/English-Version-of-Java-Study-Lesson-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值