• 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

how do i loop not using a for statement?

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


After this, i want to loop it back up into the first statement again. How do i do that?
Thanks a bunch!
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several ways to iterate in Java. At the basic level, there are 2 that you need to be familiar with (aside from the for-next):

1. the while loop. In this structure, the looping condition is evaluated before the loop is entered. The loop may never be entered, depending on the condition.

2. the do-while loop. In this structure, the looping condition is evaluated at the end of the loop. The loop will always be executed at least once, because the condition is evaluated post-loop.

in your example, clearly the do-while is appropriate. Take a look at your text...you should have something along the lines of:

 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would use a switch / case:

 
yeng xiong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do i implement:

System.out.println("Shop is not setup yet!");

into it every time when a number other than 1 is pressed?

note: i want to stay as basic as possible, within, method, iteration, arrays, recursive, do-while loops, for loops, etc...
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should set something as a boolean to decide whether or not the shop is set up... and place it into an if/else

perhaps:


or
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
== true? It's not 1st April, Janeice.
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was afraid to put



... because I didn't want anyone who might already be confused to think shopSetUp might be a numeric value, like you can do in C++

But I suppose



might be better. I didn't mean to be misleading, as the matter of fact I wanted to unconfuse...
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you write "if (shopSetUp)". It is a boolean, and that is how you write booleans. If it really is a boolean rather than a Boolean, you can't write .equals after it. Not if the compiler is awake, anyway
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic