# For Loop Help

• February 26th, 2011, 06:14 PM
nekromanik
For Loop Help
Hi
I been trying to figure out this problem for last few days but cannot find the answer.
I am trying to use nested for loops to try and create a 6 character string using letters/numbers from a array. I need it so that it starts off with one character and then adds one more etc.

Example is
a
b
..z
then
aa
ab
ac
...az

or even

a
z
aa
ba
za etc

here is my code so far

Code Java:

```char[] letters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0','1','2','3','4','5','6','7','8','9', }; boolean found = false; char[] guess = new char[7]; int pos = 0, i = 0; String word;   // while (found == false) { loop:   for (int a = 0; a<36; a++){   guess[5] = letters[i];   for (int b = 0; b<36; b++){   guess[4] = letters[i];   for (int c = 0; c<36; c++){   guess[3] = letters[i];   for (int d = 0; d<36; d++){   guess[2] = letters[i];   for (int e = 0; e<36; e++){   guess[1] = letters[e];   for (int f = 0; f<36; f++){   guess[0] = letters[f];   word = String.valueOf(guess);```

thanks
• March 15th, 2011, 03:06 PM
Tjstretch
Re: For Loop Help
I'm confused.. what are you trying to do? Your examples don't make a whole lot of sense, but I think I have it but need to be sure..

It prints aa, than adds one letter to ab, than ac, when it gets to z it restarts ba? Most of your for loops are unnecessary if thats the case, but than you have boolean found.. so I'm confused.
• March 17th, 2011, 10:36 PM
vanDarg
Re: For Loop Help
I'm not sure where you are going with this code, and I suspect you don't have much experience with for loops. I recommend reading:

The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

It explains the concept of for loops very well. The examples alone should give you a decent explanation.