Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Can't use block of statements as 'incrementer' in for loop? Date: Wed, 14 Feb 2018 11:34:55 -0500 Organization: A noiseless patient Spider Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 14 Feb 2018 16:34:58 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="0f342452f1ffb9d8f4af90f757b59460"; logging-data="14409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XWO7HGwd2ghjmQLwY4CMl" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:MKIIGbZ7uipQ/w/pBVwUxZBmZac= Xref: csiph.com comp.lang.java.programmer:38022 On 2/14/2018 11:01 AM, Robert Spanjaard wrote: > When you create a for loop, you provide an initialisation statement, a > condition, and a continue statement. Usually this continue statement is > an incrementer or decrementer, but basically it can be any statement. "Expression," not "statement." > [...] > Now, the same tutorial says "A block is a group of zero or more > statements between balanced braces and can be used anywhere a single > statement is allowed." (*2) > > But when I replace the single haha-printing statement with any kind of > block, the compiler produces an error message: > > ForDemo.java:3: error: illegal start of expression >       for (int i=1; i<11; { i++; i++; }) { >                           ^ Right. The brace-enclosed stuff is a block, hence a statement, but the `for' requires an expression -- not a statement -- in the third spot. -- esosman@comcast-dot-net.invalid One thousand seventy-one days to go.