This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes A little help on looping.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

A little help on looping..

kielmaru vasquez

Joined: Jul 12, 2011
Posts: 5
So I need to print out these numbers:

10 70 20 65 30 60 40 55 50

I have two sets of for loops, one for the 10 20 30 40 50 sequence, then another for 70 65 60 55. Since you cant have only one loop since the numbers arent in descending/ascending order.

My problem is, how can you alternate it? Execute the first number of the first loop, then print out the first number on the 2nd loop.

I tried doing nested loop:

public class Prelim07_55


public static void main ( String [] args )
int i, x;

for (i=0; i<=40 ;)
i = i + 10;
System.out.print(" " + i);

for (x=75; x>=60 ;)
x = x - 5;
System.out.print(" " + x);




But it outputs ALL the numbers on the inner loop. I want the inner loop to only execute one at a time.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60049

Please do not post the same question more than once.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: A little help on looping..
Similar Threads
Java histogram program.. bit of help required please?
How would i shuffle my deck of cards?
A little help on looping
Whats wrong with system.err?
A Hard Puzzle