• 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

reversing for loops

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm having a problem with doing revers for loops could someone help me and and explain to me why my code is not working it's still incomplete but I need the 2nd "B" at the end to count from let say 10-2 using only odd numbers it counts 10-2 but doesn't do the odd numbers only


 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ian Bray,

Welcome to CodeRanch!

Ian Bray wrote:Hi I'm having a problem with doing revers for loops could someone help me and and explain to me why my code is not working it's still incomplete but I need the 2nd "B" at the end to count from let say 10-2 using only odd numbers it counts 10-2 but doesn't do the odd numbers only


I would highly recommend to use proper punctuation, so that it would be easier to understand what you are asking. Especially this part :

I need the 2nd "B" at the end to count from let say 10-2 using only odd numbers it counts 10-2 but doesn't do the odd numbers only



Ian Bray wrote:Hi I'm having a problem with doing revers for loops


First of all, why are you reversing the loops? Is it kind of an assignment? Was there any problem while using 'normal' for loops? What was the problem? Please, TellTheDetails.

Ian Bray wrote:help me and and explain to me why my code is not working


Well, unless we know what you are trying to do, and what should be the expected output, its really difficult to assist you (even if we want to).

Also, please QuoteYourSources, UseCodeTags and note that this is NotACodeMill.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anayonkar Shivalkar wrote: . . . UseCodeTags . . . .

Since you are new, I have added the code tags for you and you can see how much better the post looks. Unfortunately, it highlights incorrect indentation, so you can’t tell just by looking which else corresponds to which if (...). Also, you should use spaces for indenting, not tabs. You also have a design problem; the main method is not intended to hold lots of code like that. I know some books show code like that, but it doesn’t teach you object‑oriented design.
If you are using Java7, you can use a switch-case with "a" "A" "b" "B" etc. as its cases.
Why are you using capital letters to start local variable names?
Why have you got Start++ as the initialisation of a for statement? That looks like very peculiar design. You should code for loops to match this example whenever possible.
Also, provided the variables stay in scope, it is probably better style to declare them as late as possible, which would be where they are initialised from the Scanner.
It is completely unnecessary to enclose your loops in those if(...) statements.

You can use this sort of loop to iterate an array backwards
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic