TalkChess.com
Hosted by Your Move Chess & Games

Author Message
Lucas Braesch

Joined: 31 May 2010
Posts: 2940

Post subject: Re: I'm not very happy with the do {} while() statement in C    Posted: Mon Feb 19, 2018 11:45 am

Michael Sherwin wrote:
mar wrote:
Michael Sherwin wrote:
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?

What "poor design" are you talking about? If you want early exit, just use break inside infinite loop. What you propose is beyond ugly.

 Code: for(;;)          {             dirPtr[j][sq] |= ((u64)1 << ts);             k += dir[j];             if (!initBoard[k])               break;             y = k / 10; x = k - y * 10 - 1; y -= 2;             ts = y * 8 + x;           }

Beauty is in the eye of the beholder. Break while an efficient solution is nothing more than a goto. And any goto is considered poor design by some. It is considered unfortunate by some that we must resort to using goto in some situations. The ugliness that you are referring to I think is that it looks like a regular while loop. I thought of that so I am now thinking do {} while () first {}

But it is just an idea.

"Beauty is in the eye of the beholder". This is such a BS argument used to justify just about anything. No, beauty in code is 99% of the time objective, and your code does not belong to the 1% exception. Your code smells, and Martin just showed you how to write it properly. Don't blame C's while syntax for your smelly code. Blame yourself.
_________________
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
Subject Author Date/Time
Michael Sherwin Sun Feb 18, 2018 8:06 am
Marco Belli Sun Feb 18, 2018 8:47 am
Michael Sherwin Sun Feb 18, 2018 9:03 am
Nguyen Pham Sun Feb 18, 2018 9:11 am
Michael Sherwin Sun Feb 18, 2018 9:21 am
Nguyen Pham Sun Feb 18, 2018 9:42 am
Ronald de Man Sun Feb 18, 2018 9:51 am
Michael Sherwin Sun Feb 18, 2018 10:07 am
Ronald de Man Sun Feb 18, 2018 10:21 am
Michael Sherwin Sun Feb 18, 2018 10:23 am
Rasmus Althoff Sun Feb 18, 2018 9:42 am
Michael Sherwin Sun Feb 18, 2018 10:05 am
Rasmus Althoff Sun Feb 18, 2018 10:27 am
Michael Sherwin Sun Feb 18, 2018 10:34 am
Michael Sherwin Sun Feb 18, 2018 10:54 am
Rasmus Althoff Sun Feb 18, 2018 11:00 am
Michael Sherwin Sun Feb 18, 2018 11:09 am
Rasmus Althoff Sun Feb 18, 2018 11:20 am
Michael Sherwin Sun Feb 18, 2018 11:48 am
Rasmus Althoff Sun Feb 18, 2018 12:40 pm
Michael Sherwin Sun Feb 18, 2018 1:56 pm
Ronald de Man Sun Feb 18, 2018 2:34 pm
Sven Schüle Tue Feb 20, 2018 12:23 am
Michael Sherwin Tue Feb 20, 2018 2:25 am
Michael Sherwin Tue Feb 20, 2018 5:39 am
Sven Schüle Tue Feb 20, 2018 10:37 pm
Michael Sherwin Tue Feb 20, 2018 11:59 pm
Fulvio Benini Wed Feb 21, 2018 10:08 am
Michael Sherwin Mon Mar 05, 2018 12:03 am
Álvaro Begué Mon Mar 05, 2018 1:03 am
Michael Sherwin Mon Mar 05, 2018 1:11 am
Álvaro Begué Mon Mar 05, 2018 1:27 am
Michael Sherwin Mon Mar 05, 2018 2:09 am
Lucas Braesch Wed Mar 07, 2018 4:06 am
Michael Sherwin Wed Mar 07, 2018 12:54 pm
Lucas Braesch Wed Mar 07, 2018 11:29 pm
Marco Costalba Fri Mar 09, 2018 8:40 am
Michael Sherwin Fri Mar 09, 2018 3:35 pm
Alcides Schulz Wed Mar 07, 2018 11:32 pm
Ed Schroder Fri Mar 09, 2018 2:59 pm
Michael Sherwin Fri Mar 09, 2018 3:25 pm
Rasmus Althoff Fri Mar 09, 2018 3:47 pm
Richard Delorme Fri Mar 09, 2018 7:07 pm
Michael Sherwin Fri Mar 09, 2018 7:43 pm
Rasmus Althoff Fri Mar 09, 2018 8:11 pm
Rasmus Althoff Sat Mar 10, 2018 9:58 am
Rasmus Althoff Fri Mar 09, 2018 8:14 pm
Robert Hyatt Sat Mar 10, 2018 4:20 am
Martin Sedlak Sat Mar 10, 2018 9:21 am
Martin Sedlak Sat Mar 10, 2018 9:29 am
Robert Hyatt Sat Mar 10, 2018 6:08 pm
Martin Sedlak Sat Mar 10, 2018 6:37 pm
Robert Hyatt Sat Mar 10, 2018 10:13 pm
Martin Sedlak Sat Mar 10, 2018 10:45 pm
Robert Hyatt Wed Mar 14, 2018 2:06 am
Rasmus Althoff Sat Mar 10, 2018 7:16 pm
Matthew Hull Sat Mar 10, 2018 9:17 pm
Robert Hyatt Sat Mar 10, 2018 10:18 pm
Rasmus Althoff Sat Mar 10, 2018 10:40 pm
Rasmus Althoff Sat Mar 10, 2018 10:54 pm
Matthew Hull Sun Mar 11, 2018 11:14 am
Rasmus Althoff Sun Mar 11, 2018 1:51 pm
Ronald de Man Sun Mar 11, 2018 12:32 pm
Rasmus Althoff Sun Mar 11, 2018 1:42 pm
Robert Hyatt Wed Mar 14, 2018 2:20 am
laurie tunnicliffe Sun Mar 11, 2018 9:16 am
Lucas Braesch Sun Mar 11, 2018 11:11 am
Ed Schroder Sat Mar 10, 2018 9:59 am
P. Kumar Mon Mar 05, 2018 4:42 am
Martin Sedlak Sun Feb 18, 2018 5:39 pm
Michael Sherwin Sun Feb 18, 2018 5:59 pm
Martin Sedlak Sun Feb 18, 2018 6:40 pm
Michael Sherwin Sun Feb 18, 2018 7:16 pm
Ronald de Man Sun Feb 18, 2018 8:39 pm
Rasmus Althoff Sun Feb 18, 2018 10:06 pm
Martin Sedlak Sun Feb 18, 2018 10:32 pm
Ronald de Man Sun Feb 18, 2018 11:53 pm
Rasmus Althoff Mon Feb 19, 2018 5:58 pm
Martin Sedlak Sun Feb 18, 2018 9:33 pm
Rasmus Althoff Sun Feb 18, 2018 7:04 pm
Ronald de Man Sun Feb 18, 2018 9:12 pm
Rasmus Althoff Sun Feb 18, 2018 10:05 pm
Robert Hyatt Tue Feb 20, 2018 5:22 am
Michael Sherwin Tue Feb 20, 2018 6:14 am
Michael Sherwin Tue Feb 20, 2018 6:33 am
Robert Hyatt Tue Feb 20, 2018 10:23 pm
Michael Sherwin Tue Feb 20, 2018 11:52 pm
Álvaro Begué Tue Feb 20, 2018 11:45 pm
Michael Sherwin Wed Feb 21, 2018 12:15 am
H.G.Muller Wed Feb 21, 2018 8:34 am
Robert Hyatt Thu Feb 22, 2018 2:21 am
Ronald de Man Thu Feb 22, 2018 12:51 pm
Robert Hyatt Fri Feb 23, 2018 4:12 am
Rasmus Althoff Thu Feb 22, 2018 5:58 pm
Eugene Kotlov Thu Feb 22, 2018 6:16 pm
Rasmus Althoff Thu Feb 22, 2018 5:54 pm
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
Michael Sherwin Mon Feb 19, 2018 2:13 pm
Robert Hyatt Tue Feb 20, 2018 5:13 am
laurie tunnicliffe Mon Mar 05, 2018 12:22 am
Michael Sherwin Mon Mar 05, 2018 1:04 am
Álvaro Begué Mon Mar 05, 2018 1:06 am
Rasmus Althoff Wed Mar 07, 2018 4:58 pm

 Jump to: Select a forum Computer Chess Club Forums----------------Computer Chess Club: General TopicsComputer Chess Club: Tournaments and MatchesComputer Chess Club: Programming and Technical DiscussionsComputer Chess Club: Engine Origins Other Forums----------------Chess Thinkers ForumChess Players ForumForum Help and Suggestions
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