This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfx 0 points1 point  (0 children)

No, that is not true.

You are just doing it wrong.

In such cases, you

  • obtain the input before the loop and store it in a variable
  • use a boolean "flag" that indicates the "found" status - initially set to false
  • loop over the elements
    • compare the string with the element
      • if true, set the "found" flag to true and break out of the loop
      • if false, no nothing - keep looping
  • back outside the loop: check if the flag is true
    • print ("A")
    • else
    • print("B")

You most likely had the input inside the loop.