While loop keeps entering an infinite loop, in my project 9 application

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: While loop keeps entering an infinite loop, in my project 9 application

Obij
Thanks. but using characters directly would not work, because I would have to use the function readChar() to request input and it does not take a String argument, like readString(String message). The argument message, in the function tells the player to input a String letter.

But I have resolved it, using a workaround as I explained in my previous post.
Reply | Threaded
Open this post in threaded view
|

Re: While loop keeps entering an infinite loop, in my project 9 application

WBahn
Administrator
Obij wrote
Thanks. but using characters directly would not work, because I would have to use the function readChar() to request input and it does not take a String argument, like readString(String message). The argument message, in the function tells the player to input a String letter.

But I have resolved it, using a workaround as I explained in my previous post.
Just because you get a String from the keyboard does not mean that you can't check the contents of the String and then put a character into your data structure.

Otherwise you are going to have to deal with how you are copying your TicTacToe board (code that I think you had in another thread); hopefully you now have a good enough understanding to see the minefield you have laid for yourself with your current implementation.

On a side note, you seem to have also fallen prey to a very common false economy in which you write lots of code before testing it with the result that you have a much harder time finding the problems that result and then, once found, have to fix lots of code because you've made the same mistake in lots of places. For instance, consider just this much of the very top of your program:

function Array inputPlayerLetter(){
       var String letter;
           var Array inputLetters;
           let letter= Keyboard.readLine("Do you want to be X or O? Please type in capital letters: ");
           
            while (~(letter = "X") | ~(letter = "O")){
              let letter= Keyboard.readLine("Do you want to be X or O? Please type in capital letters: ");
           }
...

If you had tested your program at this point, all of these issues regarding what gets stored when a String object is assigned to a variable and how to check for equality between Strings would have risen immediately to the surface. But, instead, you've written tons of code that now has to be nearly completely rethought and redone.

Incremental development and testing will almost always save time, effort, and heartache at the end of the day.
 
Reply | Threaded
Open this post in threaded view
|

Re: While loop keeps entering an infinite loop, in my project 9 application

Sai krishna
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: While loop keeps entering an infinite loop, in my project 9 application

WBahn
Administrator
STOP posting the same question over and over. Furthermore, what does your question have to do with the original poster's application entering an infinite loop?
12