ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

I'm not very happy with the do {} while() statement in C
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Michael Sherwin



Joined: 26 May 2006
Posts: 2795
Location: OH, USA

PostPost subject: I'm not very happy with the do {} while() statement in C    Posted: Sun Feb 18, 2018 8:06 am Reply to topic Reply with quote

Code:

#define FALSE  0
#define TRUE   1

#define QUIT   0
#define THINK  1
#define GETCMD 2

#define s32 signed   __int32
#define u64 unsigned __int64

void Think(void);
void Initialize(void);
void GetCmd(void);
s32 main(void);

u64 dir7p[64];
u64 dir9p[64];
u64 dir7m[64];
u64 dir9m[64];
u64 dir1p[64];
u64 dir8p[64];
u64 dir1m[64];
u64 dir8m[64];
u64 dirKn[64];
u64 dirKi[64];

s32 mode = GETCMD;

u64 *dirPtr[8] = { dir7p, dir9p, dir7m, dir9m, dir1p, dir8p, dir1m, dir8m };

void Think() {

}

void GetCmd() {
  mode = QUIT;
}

void Initialize() {
  s32 i, j, k, x, y, sq, ts;
  s32 dir[8] = { 9, 11, -9, -11, 1, 10, -1, -10 };
  s32 din[8] = { 8, 12, 18, 22, -8, -12, -18, -22 };
  s32 initBoard[120] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

  for (i = 21; i < 99; i++) {
    if (initBoard[i]) {
      y = i / 10; x = i - y * 10 - 1; y -= 2;
      sq = y * 8 + x;
      dirKi[sq] = 0;
      dirKn[sq] = 0;
      for (j = 0; j < 8; j++) {
        k = i + din[j];
        if (initBoard[k]) {
          y = k / 10; x = k - y * 10 - 1; y -= 2;
          ts = y * 8 + x;
          dirKn[sq] |= (u64)1 << ts;
        }
        dirPtr[j][sq] = 0;
        k = i + dir[j];
        if (initBoard[k])  {
          y = k / 10; x = k - y * 10 - 1; y -= 2;
          ts = y * 8 + x;
          dirKi[sq] |= (u64)1 << ts;
          do {
            dirPtr[j][sq] |= ((u64)1 << ts);
            k += dir[j];
            y = k / 10; x = k - y * 10 - 1; y -= 2;
            ts = y * 8 + x;
          } while (initBoard[k]);
        }
      }
    }
  }
}

s32 main()
{
  Initialize();

  while (mode) {
    if (mode == THINK) Think();
    GetCmd();
  }
  return 0;
}


In the do while loop I have to execute instructions that at some point will not need to be executed. It is not really a problem in this simple initiation example. But still it seems like a poor design. It would be perfect if the do while worked like this.

Code:

         k = i + dir[j];
        if (initBoard[k])  {
          y = k / 10; x = k - y * 10 - 1; y -= 2;
          ts = y * 8 + x;
          dirKi[sq] |= (u64)1 << ts;
          do {
            dirPtr[j][sq] |= ((u64)1 << ts);
            k += dir[j];
          } while (initBoard[k]) {
            y = k / 10; x = k - y * 10 - 1; y -= 2;
            ts = y * 8 + x;
          }
        }
 


If it would execute the code in the braces before looping back to the do statement. Maybe there is away around this minor dilemma. I just do not know what it is?
_________________
Regards,
Mike
Back to top
View user's profile Send private message
Display posts from previous:   
Subject Author Date/Time
I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 8:06 am
      Re: I'm not very happy with the do {} while() statement in C Marco Belli Sun Feb 18, 2018 8:47 am
            Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 9:03 am
      Re: I'm not very happy with the do {} while() statement in C Nguyen Pham Sun Feb 18, 2018 9:11 am
            Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 9:21 am
                  Re: I'm not very happy with the do {} while() statement in C Nguyen Pham Sun Feb 18, 2018 9:42 am
                  Re: I'm not very happy with the do {} while() statement in C Ronald de Man Sun Feb 18, 2018 9:51 am
                        Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 10:07 am
                              Re: I'm not very happy with the do {} while() statement in C Ronald de Man Sun Feb 18, 2018 10:21 am
                                    Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 10:23 am
      Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 9:42 am
            Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 10:05 am
                  Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 10:27 am
                        Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 10:34 am
                              Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 10:54 am
                                    Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 11:00 am
                                          Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 11:09 am
                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 11:20 am
                                                Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 11:48 am
                                                      Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 12:40 pm
      Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 1:56 pm
            Re: I'm not very happy with the do {} while() statement in C Ronald de Man Sun Feb 18, 2018 2:34 pm
            Re: I'm not very happy with the do {} while() statement in C Sven Schüle Tue Feb 20, 2018 12:23 am
                  Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Tue Feb 20, 2018 2:25 am
                        Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Tue Feb 20, 2018 5:39 am
                              Re: I'm not very happy with the do {} while() statement in C Sven Schüle Tue Feb 20, 2018 10:37 pm
                                    Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Tue Feb 20, 2018 11:59 pm
                              Re: I'm not very happy with the do {} while() statement in C Fulvio Benini Wed Feb 21, 2018 10:08 am
                                    Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Mon Mar 05, 2018 12:03 am
                                          Re: I'm not very happy with the do {} while() statement in C Álvaro Begué Mon Mar 05, 2018 1:03 am
                                                Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Mon Mar 05, 2018 1:11 am
                                                      Re: I'm not very happy with the do {} while() statement in C Álvaro Begué Mon Mar 05, 2018 1:27 am
                                                            Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Mon Mar 05, 2018 2:09 am
                                                                  Re: I'm not very happy with the do {} while() statement in C Lucas Braesch Wed Mar 07, 2018 4:06 am
                                                                        Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Wed Mar 07, 2018 12:54 pm
                                                                              Re: I'm not very happy with the do {} while() statement in C Lucas Braesch Wed Mar 07, 2018 11:29 pm
                                                                              Re: I'm not very happy with the do {} while() statement in C Marco Costalba Fri Mar 09, 2018 8:40 am
                                                                                    Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Fri Mar 09, 2018 3:35 pm
                                                                        Re: I'm not very happy with the do {} while() statement in C Alcides Schulz Wed Mar 07, 2018 11:32 pm
                                                                  Re: I'm not very happy with the do {} while() statement in C Ed Schroder Fri Mar 09, 2018 2:59 pm
                                                                        Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Fri Mar 09, 2018 3:25 pm
                                                                        Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Fri Mar 09, 2018 3:47 pm
                                                                              Re: I'm not very happy with the do {} while() statement in C Richard Delorme Fri Mar 09, 2018 7:07 pm
                                                                                    Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Fri Mar 09, 2018 7:43 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Fri Mar 09, 2018 8:11 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sat Mar 10, 2018 9:58 am
                                                                                    Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Fri Mar 09, 2018 8:14 pm
                                                                        Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Sat Mar 10, 2018 4:20 am
                                                                              Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sat Mar 10, 2018 9:21 am
                                                                                    Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sat Mar 10, 2018 9:29 am
                                                                                    Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Sat Mar 10, 2018 6:08 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sat Mar 10, 2018 6:37 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Sat Mar 10, 2018 10:13 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sat Mar 10, 2018 10:45 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Wed Mar 14, 2018 2:06 am
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Fri Mar 23, 2018 3:33 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Fri Mar 23, 2018 7:19 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Álvaro Begué Fri Mar 23, 2018 7:29 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Ronald de Man Fri Mar 23, 2018 8:51 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Ronald de Man Fri Mar 23, 2018 8:55 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Álvaro Begué Sat Mar 24, 2018 12:00 am
                                                                                          Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Fri Mar 23, 2018 4:17 am
                                                                                          Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Fri Mar 23, 2018 7:33 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sat Mar 10, 2018 7:16 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Matthew Hull Sat Mar 10, 2018 9:17 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Sat Mar 10, 2018 10:18 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sat Mar 10, 2018 10:40 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sat Mar 10, 2018 10:54 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Matthew Hull Sun Mar 11, 2018 11:14 am
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Mar 11, 2018 1:51 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Ronald de Man Sun Mar 11, 2018 12:32 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Mar 11, 2018 1:42 pm
                                                                                          Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Wed Mar 14, 2018 2:20 am
                                                                                          Re: I'm not very happy with the do {} while() statement in C laurie tunnicliffe Sun Mar 11, 2018 9:16 am
                                                                                          Re: I'm not very happy with the do {} while() statement in C Lucas Braesch Sun Mar 11, 2018 11:11 am
                                                                              Re: I'm not very happy with the do {} while() statement in C Ed Schroder Sat Mar 10, 2018 9:59 am
                                                            Re: I'm not very happy with the do {} while() statement in C P. Kumar Mon Mar 05, 2018 4:42 am
      Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sun Feb 18, 2018 5:39 pm
            Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 5:59 pm
                  Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sun Feb 18, 2018 6:40 pm
                        Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Sun Feb 18, 2018 7:16 pm
                        Re: I'm not very happy with the do {} while() statement in C Ronald de Man Sun Feb 18, 2018 8:39 pm
                              Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 10:06 pm
                                    Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sun Feb 18, 2018 10:32 pm
                                    Re: I'm not very happy with the do {} while() statement in C Ronald de Man Sun Feb 18, 2018 11:53 pm
                                          Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Mon Feb 19, 2018 5:58 pm
                        Re: I'm not very happy with the do {} while() statement in C Martin Sedlak Sun Feb 18, 2018 9:33 pm
                  Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 7:04 pm
                        Re: I'm not very happy with the do {} while() statement in C Ronald de Man Sun Feb 18, 2018 9:12 pm
                              Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Sun Feb 18, 2018 10:05 pm
                              Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Tue Feb 20, 2018 5:22 am
                                    Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Tue Feb 20, 2018 6:14 am
                                          Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Tue Feb 20, 2018 6:33 am
                                                Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Tue Feb 20, 2018 10:23 pm
                                                      Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Tue Feb 20, 2018 11:52 pm
                                          Re: I'm not very happy with the do {} while() statement in C Álvaro Begué Tue Feb 20, 2018 11:45 pm
                                                Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Wed Feb 21, 2018 12:15 am
                                                      Re: I'm not very happy with the do {} while() statement in C H.G.Muller Wed Feb 21, 2018 8:34 am
                                                            Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Thu Feb 22, 2018 2:21 am
                                                                  Re: I'm not very happy with the do {} while() statement in C Ronald de Man Thu Feb 22, 2018 12:51 pm
                                                                        Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Fri Feb 23, 2018 4:12 am
                                                                  Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Thu Feb 22, 2018 5:58 pm
                                                                        Re: I'm not very happy with the do {} while() statement in C Eugene Kotlov Thu Feb 22, 2018 6:16 pm
                                                            Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Thu Feb 22, 2018 5:54 pm
                                                                  Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Fri Feb 23, 2018 4:22 am
                  Re: I'm not very happy with the do {} while() statement in C Lucas Braesch Mon Feb 19, 2018 11:45 am
                        Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Mon Feb 19, 2018 2:13 pm
                  Re: I'm not very happy with the do {} while() statement in C Robert Hyatt Tue Feb 20, 2018 5:13 am
      Re: I'm not very happy with the do {} while() statement in C laurie tunnicliffe Mon Mar 05, 2018 12:22 am
            Re: I'm not very happy with the do {} while() statement in C Michael Sherwin Mon Mar 05, 2018 1:04 am
            Re: I'm not very happy with the do {} while() statement in C Álvaro Begué Mon Mar 05, 2018 1:06 am
            Re: I'm not very happy with the do {} while() statement in C Rasmus Althoff Wed Mar 07, 2018 4:58 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads