龙空技术网

《Java面向对象程序设计》——语句(2)

LearningYard学苑 605

前言:

此刻姐妹们对“java复合语句用什么括号”大约比较着重,小伙伴们都需要剖析一些“java复合语句用什么括号”的相关文章。那么小编也在网摘上网罗了一些对于“java复合语句用什么括号””的相关资讯,希望小伙伴们能喜欢,你们快快来学习一下吧!

今天继续为大家带来《Java面向对象程序设计》的学习。

今天的主要内容是语句概述,条件分支语句,开关语句。

Today we continue to bring you the study of Java Object Oriented Programming.

Today's main topics are statement overview, conditional branch statements, and switch statements.

01

循环语句

1.for循环语句:for语句由关键字for,一对小括号()中用分号间隔的3个表达式以及一个复合语句组成,其中的“表达式2”必须是一个求值为boolean型数据的表达式,复合语句称为循环体。“表达式1”负责完成变量的初始化;“表达式2”是指为boolean型的表达式,称为循环条件;“表达式3”用来修整变量,改变循环条件。

2.while循环语句:while语句由关键字while,一对括号()中的一个求值为boolean类型数据的表达式和一个复合语句组成,其中的复合语句称为循环体。在该语句中,表达式称为循环条件。

3.do-while循环语句

do-while循环和while循环的区别是,do-while的循环体至少被执行一次。

1. for loop statement: the for statement consists of the keyword for, a pair of parentheses ( ) with a semicolon spacing of three expressions and a compound statement, of which "expression 2" must be an expression for boolean data, and the compound statement is called the loop body. "Expression 1" is responsible for initializing the variable; "Expression 2" is the boolean expression, called the loop condition; "Expression 3" is used to fix the variable The "expression 3" is used to fix the variables and change the loop condition.

2. while loop statement: while statement consists of the keyword while, a pair of parentheses ( ) in an expression of boolean type data and a compound statement, where the compound statement is called the loop body. In this statement, the expression is called the loop condition.

3. do-while Loop Statement

The difference between a do-while loop and a while loop is that the body of a do-while loop is executed at least once.

02

break和continue语句

break和continue语句是用关键字break或continue加上分号构成的语句。

在循环体中可以使用break和continue语句。在一个循环中,例如循环50次的循环语句中,如果在某次循环中执行了break语句,那么整个循环语句就结束,如果在某次循环中执行了continue语句,那么本次循环就结束,即不再执行本次循环中循环体中的continue语句后面的语句,而转入进行下一次循环。

The break and continue statements are statements made up of the keyword break or continue plus a semicolon.

The break and continue statements can be used in the body of a loop. In a loop, for example, a loop statement that loops 50 times, if a break statement is executed in a loop, then the whole loop statement ends, and if a continue statement is executed in a loop, then the loop ends, i.e., the statement following the continue statement in the loop body in this loop is no longer executed, and the loop moves on to the next loop.

03

数组与for语句

对for语句,可以理解为“对于循环变量依次取数组的每一个元素的值”。

The for statement can be interpreted as "taking the value of each element of the array in turn for the loop variable".

04

枚举类型与for,switch语句

首先声明一个枚举类型,然后就可以用该枚举类型声明一个枚举常量了。该枚举变量只能取枚举类型中的常量,通过使用枚举名和“.”运算符获得枚举类型的常量。可以使用for语句遍历枚举类型中的常量,允许switch语句中表达式的值是枚举类型。

First declare an enum type, then you can declare an enum constant with that enum type. The enum variable can only take constants of the enum type, by using the enum name and the "." operator to get the constant of the enum type. You can use the for statement to iterate through the constants of the enumeration type, allowing the value of the expression in the switch statement to be of the enumeration type.

参考资料:文字:百度;图片:微博;翻译:百度翻译

本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。

标签: #java复合语句用什么括号