The Goto statement provides an arbitrary jump inside the method, which is applied in a special scenario.And assuming that an object executes a method, we expect that any other object can capture it, and then perform some operations on its own, so what can be done?Classvoid notices the world () {/ ///to map the contents of the notice to the sky, And the sky is the common area between heaven and earth, all objects between heaven and earth can access i
Reposted from Sina Blog:
1: Why not use the GOTO statement?
Source (from Wikipedia ):
Goto is a statement that can be found in many computer programming languages. It is an English word.GoAndTo. When executing this statement, it transfers the control process to another statement unconditionally (also called "jump "). The jump statement must specify the mark. in different languages, the mark can be an identi
Goto statements are notorious in C/C ++, and even some books or company programming specifications. The result is that when some programmers see the goto statement being used in a program, they instinctively think that the program is "junk ". In addition, some programmers feel that they are not professional because they use the goto statement. In fact, everything
// ================================================ ========================================// Title:// How to Write elegant code (1) -- flexible use of Goto and _ Try// Author:// Norains// Date:// Thursday 16-July-2009// Environment:// Wince5.0 + vs2005// ================================================ ========================================Is goto a poison? Where you can use
Once upon a time, how powerful goto was to let the cool man Bloom their superb technologies. Once upon a time, goto became the first of all evil, the goto example only appears in the textbook. There are too many reasons not to use goto, but sometimes we want to use the goto
Whether goto statements should be used
A goto statement is also known as an unconditional transfer statement , which is usually used in conjunction with a conditional statement to change the flow of the program, allowing the program to go through the statements identified by the statement label .
Historically, there has been a debate over whether GOTO statem
The goto statement is an unconditional transfer statement that is used in the following format:Goto statement label;Where the label is a valid identifier, with a ":" (colon) that appears somewhere inside the function, after the goto statement is executed, the program jumps to the label and executes the subsequent statement.In addition, the label must be in a function with the
For goto statements, it is no longer recommended in C/C ++, and there is no goto in Java. Why does the GOTO statement be re-used in C?
First, let's take a look at the usage of the GOTO statement in C:1) The basic function is to execute the statement in the place where the user jumps to the label as before.// Exp1 vali
intDo_listen (Const Char* Host,intPortintbacklog) { intFamily =0; intLISTEN_FD = Do_bind (host, Port, IPPROTO_TCP, family); if(Listen_fd 0) { return-1; } if(Listen (listen_fd, backlog) = =-1) {close (LISTEN_FD); return-1; } returnlisten_fd;}This is a piece of code to create a protocol-independent listening socket, where three of the goto statements are used, because the getaddrinfo (...) is called in front of it. ) function, the funct
After work, in the reading of the code written by foreigners, found a very interesting thing, we often say goto statement is harmful, mainly it jumps to jump, upset logic. But Goto also has benefits, such as single-exit, unified freeing of memory aspects, the next look at a function of MAPI initializationintMapiinit () {intResult =Dt_error; HRESULT HRESULT=S_FALSE; HANDLE Hlock=NULL; BOOL bLocked=FALSE; DWO
The goto operator can be used to jump to a specified position in a program. The target location can be marked with a colon for the target name. The Goto in PHP has a certain limit and can only jump in the same file and scope, which means you can't jump out of a function or class method, and you can't skip to another function. You also can't jump into any loops or switch structures. A common use is to jump o
The GOTO statement is a reserved word in Java and is not implemented. However, in other languages (C), Goto is a valid keyword.Although the break and continue supported in Java can implement the GOTO statement function, I personally summarize that their usage is similar.
First, the label requirements in Java are very strict.The label must be in front of a loop, w
1.GOTO, mainly used for jumping, but will disrupt our program logic, generally do not use, it can realize the function of Return,exit2.RETURN, return to program end, end program3.EXIT, mainly used to exit the current loop, equivalent to break in Java.4. To implement the functionality of continue in Java, you can use a custom exception methodThe comparison between them:--the goto here is equivalent to the fo
Objective
A goto statement is also called an unconditional transfer statement, and its basic form is as follows:
Statement marking by a valid identifier and symbol ";" , where the identifier's naming convention is the same as the variable name, which consists of letters, numbers, and underscores, and the first character must be a letter or an underscore. After the goto statement is executed, the program j
The GOTO keyword appears early in the programming language. In fact, Goto is the ancestor of the program control structure of assembly language: "If condition A,
Jump here, or jump there. " If you read the assembly code generated by almost any compiler, you will find that the program control contains many
Jump. However, Goto is at the level of the source jump, so
condition of the execution loop is true.Reference: The use of goto statements is not advocated since the late 60. ...... All programs that use Goto can be rewritten without a goto.Note: Goto is a very controversial statement, the language of multi-book suggestions for less or not to use it, my personal habits are determined not to use. However, I do not know the
Regarding the use of the goto statement, it is difficult to use it technically. When I write this text about the use of the goto statement, I think it is difficult for beginners to grasp it if the goto is in another position from a complicated execution state. In a multi-nested loop judgment, the number of program execution paths is very large. After jumping out
(! AdjustTokenPrivileges (hToken ,...)){CloseHandle (hToken );CloseHandle (hProcess );
Return FALSE;}
CloseHandle (hToken );CloseHandle (hProcess );
Return TRUE;}In this way, new problems are raised. The cleanup task is troublesome each time when return FALSE is returned. If a new HANDLE is introduced in each step, subsequent cleanup will become very heavy. Someone recommends do... The while (0) structure. Someone recommends goto. The two forms are -
Once upon a time, Goto is how to let New bloom their superb skills
Once upon a time, Goto became the head of all evils.
Once upon a time, the Goto only example in the textbook will appear
There are too many reasons not to use Goto, but sometimes, we want to use the function of Goto
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.