Here is a demo for anyone that wants to use for loops. It demonstrates the for (with index) and the for each (without index). Each has its own particular usage and this shows one way that it can be used. In the future I may publish a more practical use of each, but for now this is a good start. I have also attached the video and the files we created in Netbeans.
For loop with index:
for (int i = 0; i < str.length(); i++)
{ //Start for loop operations
// now we can pick through this
// string to print only e's (remember that
// h is 0, e is 1)
if (str.charAt(i) == 'e')
{
System.out.printf("e seen at char %s", i);
}
} //End for loop operations
For each loop without index:
for (char ch : str.toCharArray())
{
if (ch == 'e')
{
// This should only print out once
System.out.println("e reached");
} //end if
} //end for
Executable (Captivate) Video Video.zip
Netbeans Project Project.zip
Please feel free to leave comments or email me if you have any questions.