How do I loop this if statement from my program?
if (fileNames.contains(".txt")) {
System.out.println("Text File:" + fileNames);
fileNames = scan.nextLine();
}
else {
System.out.println("");
fileNames = scan.nextLine();
}
}
Printable View
How do I loop this if statement from my program?
if (fileNames.contains(".txt")) {
System.out.println("Text File:" + fileNames);
fileNames = scan.nextLine();
}
else {
System.out.println("");
fileNames = scan.nextLine();
}
}
Do you know how to write loops?
Control Flow Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
I think you need to add a for loop and how many times does it need to loop, what's the purpose of the code?
Try putting the if/else statement between this:
for (int i=?; i<? ;i++)
{
}
Question marks depend on number of times you want it to loop.
int i probably equals 0.
Sorry if this does not help I am new to this too.
What exactly you want to do?Quote:
How do I loop this if statement from my program?
We can't just read minds. Though we can assume but you not assumptions will never always lead you to the solution. So ask a proper question and get proper answer. Well, if you don't really know the loops, see Reply # 02 to your thread and you will get your answer.
I suggest you to take a look to while loop. It makes possible to iterate code while a statement is true (for example while your file has next lines to be read).