lundi 7 janvier 2019

If condition being ignored

I'm currently writing code for a game called Caladont.The game is about first player saying the word and the next one has to say the word that starts with last two letters of previous word.The problem comes when I want to check if word contains less than 3 letters or if it's empty.In the first cycle when list for filling is still empty,everything is fine.However,after I type for example 5 or more words,and type a single letter or leave it empty,it prints two "You've lost!" messages,which means that code from if statement is being ignored since it changes bool variable to false and is supposed to exit the While loop.

I've tried replacing ok = false with Exit While in condition which checks if words contains less than 3 letters and it worked,but I want to understand what is the problem.The code is here:

https://github.com/whistleblower91/VB.net/blob/master/Caladont%20game

Any solutions?

Aucun commentaire:

Enregistrer un commentaire