Hi all,
hopefully someone can help me with my problem or point me in the right direction.
I have a simple for loop that just counts up to 6 within the loop is an if statement that checks the users input and then compares that input with results stored in an array. The for loop count just passes in the value of i where i is the location in the array.
This part is all fine, my problem lies with the else. I want it to check the entire array before producing the else statement that the input cannot be found. At the moment it returns the else statement at the end of each run of the loop when the result doesn't match.
I want it to only return the else statement if it finds no matches in the entire array.
I'm only relatively new to this so please be kind
Thanks in advance!
Well you could count the cases where it has been found in a seperate variable ( defined outside the loop) and then check after the loop if the value equals 0 (no results found) and execute your "else" commands there
Or alternatively define a boolean variable (f.e. Boolean dummy = false;), set it to false and in your loop set it to true when an element is found..after the loop just check for the else case with
If (!dummy){
// else code here
}
Thanks PumpAction, they both make perfect sense.
It was one of those things I knew would be easy, I ju.st was just thinking about it the wrong way. As long as it works I'm happy
Signature/Avatar nuking: none (can be changed in your profile)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum