If Statement Problems

Hello,

I’m coming back to Tads after a bit of a break. I’ve got the old thread below to recall the meat of the lessons I was getting, but I’m caught up on a simple snag. For some reason data is not being checked in the if statement. I’ve set breakpoints and checked the data. Gender on me is getting set to ‘M’ but the loop goes infinitely.

Thanks for any help :slight_smile:

 genderAccept = nil;
        
        while(!genderAccept)
          {
              if(me.gender != 'M' || me.gender != 'F')
               {
                 
                 "\b Enter gender: M/F \n";
                  me.gender = inputLine();
                    
                }else{
                    
                    genderAccept = true;
                }
          }

Your || should be &&.

What Michel said, plus you should convert the input to uppercase in case the player types in lowercase:

me.gender = inputLine().toUpper();

Also, if you want to go completely OCD on not writing more code than you need to (always a good thing,) then:

do { "\b Enter gender: M/F \n"; me.gender = inputLine().toUpper(); } while (me.gender != 'M' && me.gender != 'F');

Works great. I thought I had tried using && as a second test, and was using uppercase M through shift. Was aware of needing to uppercase the string in the code, but hadn’t implemented it yet. I guess it just didn’t want to work this morning, lol. I tried using && just now and it worked fine :stuck_out_tongue: Anyway, I implemented your do loop, as ir was the better choice. Thanks for the tip.