Like if I want to check whether a string is a palindrome or not, how can I Implement it using two simultaneous loops so that it can be done in the shortest number of lines?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since this is almost certainly a homework, here is an explanation of the approach with no code.
You do not need two loops, you need two loop variables. Start the first one at the beginning of the word, and the second one at the end, compare the characters at loop indexes, and return false if they are different. If the characters are the same, move to the next iteration by advancing the front index forward and the back index backward. Stop when the front index is equal to or greater than the back index.
Here is the syntax that lets you use two loop variables in a single loop: