Controlling Execution

同上一章,本章依然比较简单、基础,因此只是做一些总结性的笔记。

1、不像C和C++那样(0是假,非零为真),Java不允许用一个数字作为boolean值。

2、C中,为了给变量分配空间,所有变量的定义必须在代码块前面。而C++和Java中没 有这个限制,它允许更加自然的代码风格,而且使得代码更容易理解。

3、使用Foreach语法,我们不比创建一个用来遍历各个项的整型值,foreach自动的为我们提供每一个项。

4、如果在返回值为void的方法中没有return语句,那么它隐式地在方法的结尾处返回,因此return语句并不总是必须的。然而,如果方法声明返回任何非void类型,我们必须保证代码的每个执行路径返回恰当的值。

5、Java允许在循环体之前设置标签,并且循环体和标签之间不能有任何语句,它的主要作用是可以跳出多层循环,而break和continue只能打断当前的循环。

6、The switch statement is a clean way to implement multiway selection(i.e., selecting from among a number of different execution paths), but it requires a selector that evaluates to an integral value, such as int or char. If you want to use, for example, a string or a floating point number as a selector, it won’t work in a switch statement. For non-integral types, you must use a series of if statements. BTW, Java SE5’s new enum feature helps ease this restriction, as enums are designed to work nicely with switch.

时间: 2024-10-12 12:34:18

Controlling Execution的相关文章

值得纪念的一次编程

楼主有点小白,个人觉得值得纪念,不喜勿喷. 最近在看java编程思想,遇到了求吸血鬼数的那一题,自己做的时候是把四位数分别放到数组arr里面,然后建立两个数组分别存arr中的两位.之后就遇到了许多问题,比如:如何将已经放入a数组的数不放入b数组,如何遍历数组使numa和numb不会重复计算等.其中将已经放入a数组的数不放入b数组总感觉遍历arr会导致循环太多.始终想不出来,然后看答案了. 答案是这样子的. public static void main(String[] args) { int[

使用Unity3D50个技巧-50 Tips for Working with Unity (Best Practices)

原文: 50 Tips for Working with Unity (Best Practices) About these tips These tips are not all applicable to every project. They are based on my experience with projects with small teams from 3 to 20 people. There's is a price for structure, re-usabilit

Exception handling

https://en.wikipedia.org/wiki/Exception_handling In general, an exception breaks the normal flow of execution and executes a pre-registered exception handler. The details of how this is done depends on whether it is a hardware or software exception a

Application binary interface and method of interfacing binary application program to digital computer

An application binary interface includes linkage structures for interfacing a binary application program to a digital computer. A function in a relocatable shared object module obtains the absolute address of a Global Offset Table (GOT) in the module

Indy10 控件的使用(2)TidTCpServer组件学习

Indy10 控件的使用(2)TidTCpServer组件学习 (2012-05-18 15:16:53) 转载▼ 标签: indy10 lazarus idtcpserver 分类: Indy10 以下来自英文原版帮助文件,文桓英语不好,翻译了老半天.有错误的地方见谅,别骂我. TIdTCPServer = class(TIdComponent) Description TIdTCPServer is a TIdComponent descendant that encapsulates a

PatentTips - Controlling TSC offsets for multiple cores and threads

BACKGROUND Many processors include a time stamp count (TSC) counter which is typically implemented as a counter that increments at a fixed rate. Some known TSC counters are clocked at a bus clock rate and a multiplier value is added each bus clock cy

[RxJS] Stopping a shared observable execution

ConnectableObservable has the connect() method to conveniently dictate the start of the shared execution of the source Observable. However, we need a mechanism to dictate the stop of the shared execution, otherwise a leak happens. This lesson will te

Using a USB host controller security extension for controlling changes in and auditing USB topology

Protecting computer systems from attacks that attempt to change USB topology and for ensuring that the system's information regarding USB topology is accurate is disclosed. A software model is defined that, together with secure USB hardware, provides

PatentTips - Controlling voltage and frequency

BACKGROUND OF THE INVENTION Mobile devices, such as but not limited to personal data appliances, cellular phones, radios, pagers, lap top computers, and the like are required to operate for relatively long periods before being recharged. These mobile