Logically I'm having trouble on where and how to create an if/else for the user input. Simply I just want to give the user chances to re-enter there input if there input could not be found in the txt file. My first thought was to put the else statement in that while loop but that continue value is kinda interfering. Anybody have a clue? I would really love to get help because this is the last issue I have on my final project, then I'll finally have my creation done =)
On your second code box that's what I tried doing, I put an else in there but I get an error saying "else without if". When I got rid of continue it compiled fine but that messed up everything during runtime and I have no idea how to change up the code. Since I have no idea how to change up the code I want to leave that continue their. Is their another way to by pass and throw that else in their?
George Avilez wrote:On your second code box that's what I tried doing, I put an else in there but I get an error saying "else without if". When I got rid of continue it compiled fine but that messed up everything during runtime and I have no idea how to change up the code. Since I have no idea how to change up the code I want to leave that continue their. Is their another way to by pass and throw that else in their?
You can't put an "else" anywhere. It has to come right after the "if", or as you noticed, you will get an "else without if" compile error.
It's not much of help sry. I know how to use if/else. Like I said the continue is throwing everything off for me, that if/else DOES work if there is no continue. There is no examples out there to show what to do after with that continue, unless I missed it. That's all I'm asking, first time using that value so idk how to properly syntax it...
George Avilez wrote:It's not much of help sry. I know how to use if/else. Like I said the continue is throwing everything off for me, that if/else DOES work if there is no continue. There is no examples out there to show what to do after with that continue, unless I missed it. That's all I'm asking, first time using that value so idk how to properly syntax it...
To be blunt... if you know how to use if/else, then you know that the code you presented is *not* valid Java syntax. This means that you are presenting pseudo code, in order to convey what you want. Unfortunately, for me, I can't decipher what you are trying to do from the pseudo code. Perhaps it would help if you re-explain the logic that you are attempting to achieve?
And it has nothing to do with "continue". Replacing that line with any other valid statement will yield the same error.
Well what the code is doing right now is asking for a user input, then the code will grab all the strings from the txt file and compare the users input with each string/line from the txt file. If there is a match then that string is deleted off the file. This works perfectly, but I want the code to also let the user know that there is no match in case the user enters an input that doesn't match with anything. ANd possibly loop them back to re-enter an input. As of right now if they enter an input that doesn't match then the program will still end correctly but no changes are made to the file.
George Avilez wrote:Well what the code is doing right now is asking for a user input, then the code will grab all the strings from the txt file and compare the users input with each string/line from the txt file. If there is a match then that string is deleted off the file. This works perfectly, but I want the code to also let the user know that there is no match in case the user enters an input that doesn't match with anything. ANd possibly loop them back to re-enter an input. As of right now if they enter an input that doesn't match then the program will still end correctly but no changes are made to the file.
The pseudo code (the portion with the if/else) that you presented does string trimming, and printing. It doesn't do anything of what you described here.
Yeah true. SO Am I better off just making a different while loop with an if/else that focuses on whether the input could be found on the txt file? Then break out of it if there was on found and take it straight to the while loop I have?
George Avilez wrote:On your second code box that's what I tried doing,
Err, the second code box is syntactically exactly the same as the first code box. The only difference is the formatting.
George Avilez wrote:I put an else in there but I get an error saying "else without if". When I got rid of continue it compiled fine but that messed up everything during runtime and I have no idea how to change up the code.
I've no idea why you would even want to put an else in there, what are you hoping to achieve with this else clause?
George Avilez wrote: Since I have no idea how to change up the code I want to leave that continue their.
I've shown you the code to get rid of the continue so I don't understand why you "have no idea how to change the code".
George Avilez wrote:Yeah true. SO Am I better off just making a different while loop with an if/else that focuses on whether the input could be found on the txt file? Then break out of it if there was on found and take it straight to the while loop I have?
You absolutely need a different loop if you want to repeatedly ask for an entry until you get one that is found. You can't do it with the one you currently have as that just loops over the lines in the file and for each user entry you need to repeat this process.
You absolutely need a different loop if you want to repeatedly ask for an entry until you get one that is found. You can't do it with the one you currently have as that just loops over the lines in the file and for each user entry you need to repeat this process.
Thank you, this one makes sense to me and was basically what I was asking earlier when I asked:
Or are you saying I should create another while loop just to check if the user input is available?
Thanks for the help
Post by:autobot
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards