Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1931071.aqSPkdTlGX@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 27 Dec 2011 18:27:03 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit Subject: Re: Simulate goto Newsgroups: comp.lang.javascript References: <4ef9a823$0$6842$e4fe514c@news2.news.xs4all.nl> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 105 NNTP-Posting-Date: 27 Dec 2011 18:27:04 CET NNTP-Posting-Host: fb540243.newsspool3.arcor-online.net X-Trace: DXC=K=T`:7HlNO;_A0jCfgHO6>McF=Q^Z^V384Fo<]lROoR18kF "Archos" schreef […] >> I'm trying to simulate the goto statement but I get an error >> >> === >> function testGoto() { >> var isFirst = true; >> >> skipPoint: >> alert("Using goto\n"); >> >> if (isFirst) { >> isFirst = false; >> continue skipPoint; >> alert("This part is skipped"); >> } >> } >> === >> >> SyntaxError: label not found >> continue skipPoint; > > The error may have more to do with 'continue' than with the label. > Check where you can use a continue statement - I think it is restricted to > for- and while- loops. You are mistaken. The `continue' statement, like the Labelled Statement is just another /Statement/, and it can be located anywhere in a /Program/: ,-[ES 5.1] | | 14 Program | | Syntax | | Program : | SourceElements_opt | | SourceElements : | SourceElement | SourceElements SourceElement | | SourceElement : | Statement | FunctionDeclaration ,-[ibid.] | | 12 Statements | | Syntax | | Statement : | Block | VariableStatement | EmptyStatement | ExpressionStatement | IfStatement | IterationStatement | ContinueStatement | […] | LabelledStatement | […] | | 12.3 Empty Statement | | Syntax | EmptyStatement : | ; | | […] | 12.7 The continue Statement | | Syntax | | ContinueStatement : | continue ; | continue [no LineTerminator here] Identifier; | | […] | 12.12 Labelled Statements | | Syntax | | LabelledStatement : | Identifier : Statement `skipPoint' is an /Identifier/ and – through Automatic Semicolon Insertion (ASI) – an /EmptyStatement/ is a /Statement/. One could try placing the /ExpressionStatement/ – alert(…) – at the same line as the label, but that should not be necessary in a conforming implementation (which implementation has been tested with?). That said, it is certainly not a good idea to "simulate the goto statement". Please do not post attribution novels: PointedEars -- > If you get a bunch of authors […] that state the same "best practices" > in any programming language, then you can bet who is wrong or right... Not with javascript. Nonsense propagates like wildfire in this field. -- Richard Cornford, comp.lang.javascript, 2011-11-14