• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Infinite loop or no loop

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone.

I've just started to learn - I've read "Java in Easy Steps" and am now looking to write a simple (not for me!) code.

I want to write a program that finds the size of a wall panel when given the size of the actual wall (I'm a vinyl printer for a living).

This is done by entering the wall size eg, 6000mm and then this number been devised (starting @ 1) to see how many panels are needed to cover the wall.

This size is governed by the size of the material which is 1500mm wide.

For now I want to leave the wall size as a static int while I write the first part of the coding.

I've tried "do while" loops but either get an infinite loop ("6000" printing repeatedly) or just one iteration.

Am I using the correct conditional code?

This is what I have -




If anyone can point me in the right direction I would be grateful!
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greeting - welcome to the site.

for your next post please use code tags so that your code will keep the formatting.

But to your issue - look at the body of the loop -- where in there do you change the value of Panel? How do you expect to break out of the loop if you never change the condition that controls the loop?

-steve
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have added the code tags: doesn't it look better now

And welcome again.
 
Sid Dixon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that - realised I was concentrating on the wrong int.

Came up with the following code and this works (sorry copied from Netbeans program so no line numbers again) -

 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sid,

The problem with no line numbers is not that you are copying from netbeans, but when you post the code in the text area you need to click on the Code button above the text area then post the text between the start and stop code tags.

[ code=java ]code goes here [ /code ]

note: i added space chars so you can see the code tags.... your code will look like what your original post that Campbell was kind enough to update for you.

I suggest that you edit your post above so that you can see how it works and please use these codes in any future post that includes code

-steve
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He can't edit the post after a reply; I went back and did it for him.

That code looks as if you are guessing. You can guess 1000000 times and (if all the guesses are different) there is a good chance you will get a working solution. I thought the first attempt at the loop was better except you never reduced anything. Or you can work it out and get it to work first time.
What you are doing now is dividing. That is one way to work out how many widths you need, but not in a loop. A 12′ wide wall will take 5 widths if they are 2′ 6″ wide. To get that into integer arithmetic, change it all to inches. 144 ÷ 30 is 4 in integer arithmetic, remainder 24, so you need 5 widths.
You can work out the loop more easily if you have three variables: width of wall, width of paper and wall remaining. I presume you are counting widths and parts of widths.
 
Sid Dixon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the comments.

I don't think I explained clearly what I intended.

I wanted a code that would give the final panel size of the wall ie, all panels are equal width.

This is the first part of what I want to achieve.

I now what to be able to input the wall size so the code can be used in practice.

Below is what I have up to date - starting on the next part now so hopefully you'll be able to have a look shortly.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic