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();
}
}
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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?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).