Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38022
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Can't use block of statements as 'incrementer' in for loop? |
| Date | 2018-02-14 11:34 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <p61ofi$e29$1@dont-email.me> (permalink) |
| References | <p61mgq$10r6$1@gioia.aioe.org> |
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.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can't use block of statements as 'incrementer' in for loop? Robert Spanjaard <spamtrap@arumes.com> - 2018-02-14 17:01 +0100
Re: Can't use block of statements as 'incrementer' in for loop? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-14 11:13 -0500
Re: Can't use block of statements as 'incrementer' in for loop? Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-02-14 11:34 -0500
Re: Can't use block of statements as 'incrementer' in for loop? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-14 10:57 -0800
Re: Can't use block of statements as 'incrementer' in for loop? Robert Spanjaard <spamtrap@arumes.com> - 2018-02-15 12:05 +0100
Re: Can't use block of statements as 'incrementer' in for loop? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-15 04:49 -0800
csiph-web