Advertisement
AvengersAssemble

While vs Do

Sep 13th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. //do
  2.  
  3.  do //אם מתקיימת רמאות, הלולאה תימשך
  4.                     {
  5.                         Console.WriteLine("Select row, then press 'enter' (return), then select column."); //הסבר על בחירת מיקום
  6.                         int row = int.Parse(Console.ReadLine()); //משתמש בוחר מיקום
  7.                         int column = int.Parse(Console.ReadLine());
  8.                         if (row > 3 || row < 1 || column > 3 || column < 1) //בודק שהמספר בטווח
  9.                             Console.WriteLine("Invalid row/column! There are only 3 rows and 3 columns on the board!\nPlease choose again.\n");
  10.                         else if (board[column - 1, row - 1] == 'X' || board[column - 1, row - 1] == 'O') //בודק רמאות
  11.                             Console.WriteLine("You cannot overwrite you/your friend! Please choose again.");
  12.                         else //מתקיים אם הבחירה תקינה
  13.                         {
  14.                             board[column - 1, row - 1] = userType;
  15.                             cheating = false;
  16.                         }
  17.                     }
  18.                     while (cheating);
  19.  
  20. //while
  21.   while (cheating) //לולאה שמתקיימת אם נמצאת רמאות
  22.                     {
  23.                         Console.WriteLine("Select row, then press 'enter' (return), then select column."); //הסבר על בחירת מיקום
  24.                         int row = int.Parse(Console.ReadLine()); //משתמש בוחר מיקום
  25.                         int column = int.Parse(Console.ReadLine());
  26.                         if (row > 3 || row < 1 || column > 3 || column < 1) //בודק שהמספר בטווח
  27.                             Console.WriteLine("Invalid row/column! There are only 3 rows and 3 columns on the board!\nPlease choose again.\n");
  28.                         else if (board[column - 1, row - 1] == 'X' || board[column - 1, row - 1] =='O') //בודק רמאות
  29.                             Console.WriteLine("You cannot overwrite you/your friend! Please choose again.");
  30.                         else //מתקיים אם הבחירה תקינה
  31.                         {
  32.                             board[column - 1, row - 1] = userType;
  33.                             cheating = false;
  34.                         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement