Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

continue? break?

Status
Not open for further replies.

jimache

Programmer
Feb 26, 2003
15
US
Hi. I am a bigginer in java and I really need help. When I run the program my while loop does not executes....what am I doing wrong. Can somebody help me( the GameBord class and its methods validMove, printBoard, and updateBoard are corect; the program should ask the user to enter 2 interger; the moves of the peg board game; until no more legal moves are left). Thank You.
below is my program:


import java.io.*;
class P4
{
public static GameBoard pegBoard;
public static int move;
public static int piece;

public static void main(String args[])

{


System.out.println(" xxxxxxxx");
System.out.println(" xxxxxxxxxxx\n");

System.out.println(" ______");
System.out.println(" / 0 \\");
System.out.println(" / 1 2 \\");
System.out.println(" / 3 4 5 \\");
System.out.println(" / 6 7 8 9 \\");
System.out.println(" /10 11 12 13 14\\");
System.out.println(" ----------------\n");

init();
pegBoard.printBoard();

while(endOfGame() )
{
getInput();
if (pegBoard.validMove(move, piece))
{
pegBoard.updateBoard(move, piece);
pegBoard.printBoard();
}
else
{
System.out.println(" Invalid Move");
getInput();
}
}
System.out.println("GoodBye");

}

public static void init()
{

int i;
pegBoard= new GameBoard(15);
for(i=0; i< 15; i++)
{
pegBoard.board='*';
}
pegBoard.board[12]=' ';
}

public static void getInput()

{
System.out.print(&quot; Which piece would you like to move? &quot;);
piece = UserInput.readInt();
System.out.print(&quot; Where would you like to move the piece? &quot;);
move = UserInput.readInt();
}

public static boolean endOfGame()
{

int i,j;
boolean r = true;

for(i=0; i< pegBoard.board.length; i++)
{
for(j=0; j<pegBoard.board.length; j++)
{
if(pegBoard.validMove(i,j) )
{
r =true;
continue;
}
else
r = false;
}
}
return r;
}
}
 
If the getInput() method isn't being called, then the endOfGame method must be returning false.

So, in the endOfGame method; won't the &quot;continue&quot; simply breakout of the inner &quot;for&quot; loop, therefore the outer loop will still result in r=false.

By the way, are you developing this sofware in a development tool, such as JBuilder? These have good debuggers that allow you to step through the code, I would recomend the Personnel edition of JBuilder 8 (it's free for non-commercial use)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top