aspose file tools*
The moose likes Beginning Java and the fly likes reversing for loops Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reversing for loops " Watch "reversing for loops " New topic
Author

reversing for loops

Ian Bray
Greenhorn

Joined: Jul 08, 2012
Posts: 1
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


Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

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.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40041
    
  28
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reversing for loops