• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for loop in constructor

 
Marco Vanoli
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to put a cicle for in a class costructor?
I tryed but it doesnt' work, however no compilation errors in output..
If it is's not possible why?

tnk

[ September 14, 2005: Message edited by: Marco Vanoli ]
[ September 14, 2005: Message edited by: Michael Ernest ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a cicle?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you mean. could you post your code? and tell us exactly what you think it SHOULD be doing vs. what it IS doing.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing he means "cycle" -- we call them "loops".

So "Is it possible to have a for loop in a constructor?" Yes, absolutely. Here's one:


 
koushik maiti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do u mean by a circle ? plz give ur correct meaning...
bye
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do u mean by a circle ? plz give ur correct meaning...

While we're making requests...

Please make the extra effort to write out words such as "please", "you", and "your". The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.

http://faq.javaranch.com/view?UseRealWords

Thanks!

P.S. I don't see where the OP mentioned a "circle"...
[ September 14, 2005: Message edited by: Steve Morrow ]
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've edited the topic title for clarity, but left the term 'cicle' in order to support the discussion so far.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my guess is that when the Original Poster (OP) wrote "cicle", Ernest took it to mean cycle = loop. My first thought, too, what they meant "circle".

Now, assuming Ernest was correct, that still doesn't help the OP with why HIS version didn't work. So, again, if Marco could post his code and explain what he thinks it SHOULD do vs. what it DOES do,

p.s. Steve, do you see the irony in asking someone to spell out words, then you yourself use the abberviation OP???

[ September 14, 2005: Message edited by: fred rosenberger ]
 
Marco Vanoli
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol what chaos
Yes Ernest, i wanted to say loop!
In Italy we say "ciclo" for loop so at the moment i used cicle, but the right word was cycle.. however also it was wrong.. my english little poor..

Returning to the topic before yesterday i thought that loop in a constructor is possible but using this code nothing happened..


I want to istantiate class Setting and get immediatly the list classNames filled of 10 javabens.. probably i am wrong on something..
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you need a constructor for you Setting class. The only method you have is

public Setting2(){...}.

A proper constructor uses the same name as the class. So for you it would be

public Setting(){...}.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see two problems:

1) Your constructor name does not match your class name.

2) Your loop won't run if i is set to zero and the loop should only run if it is equal to 10. You probably meant to write:
 
Marco Vanoli
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ernest:
I see two problems:

1) Your constructor name does not match your class name.

2) Your loop won't run if i is set to zero and the loop should only run if it is equal to 10. You probably meant to write:

oh my god what an idiot error

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic