Code: Select all
do {
int success = read_some_input();
if(success) {
process_input();
}
} while(success);
Moderators: hgm, Rebel, chrisw
Code: Select all
do {
int success = read_some_input();
if(success) {
process_input();
}
} while(success);
Code: Select all
void Initialize() {
s32 i, fs120, ts120, fs64, ts64;
s32 dir[8] = {9, 11, -9, -11, 1, 10, -1, -10};
s32 din[8] = {8, 12, 19, 21, -8, -12, -19, -21};
s32 isOnBoard[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 (fs64 = 63; fs64 >= 0; fs64--) {
fs120 = SQUARE120(fs64);
for (i = 0; i < 8; i++) {
ts120 = fs120 + din[i];
if (isOnBoard[ts120]) {
dirKn[fs64] |= BIT64(SQUARE64(ts120));
}
}
for (i = 0; i < 8; i++) {
ts120 = fs120 + dir[i];
if (isOnBoard[ts120]) {
dirKi[fs64] |= BIT64(SQUARE64(ts120));
do {
dirPtr[i][fs64] |= BIT64(SQUARE64(ts120));
ts120 += dir[i];
} while (isOnBoard[ts120]);
}
}
}
}
I tried to come up with a better term when I started using that. The runner-up for me was while (ALWAYS) {} The most succinct is while (1) {}hgm wrote:If you don't like 'break', it is easily avoidable at the price of some extra indentation:'while(FOREVER)' sounds linguistically broken. I would prefer 'for(EVER)' or 'while(UNBROKEN)'.Code: Select all
do { int success = read_some_input(); if(success) { process_input(); } } while(success);
Code: Select all
one_more_time:
...
if (finished)
goto done;
...
goto one_more_time;
done:
...
Here you go:hgm wrote:I would prefer 'for(EVER)' or 'while(UNBROKEN)'.
Code: Select all
#define EVER ;;
...
for(EVER)
{
do_stuff();
}
Real code sample:bob wrote:The most succinct is while (1) {}
Code: Select all
#define PIGS_DO_NOT_FLY 1u
...
while (PIGS_DO_NOT_FLY)
{
...
}
Code: Select all
#define EVER 1
EVER&EVER;
for(; EVER&EVER;)
{
int You=1;
//That shines in me
//like the morning sun
}
I've used that millions of times in years gone by. Particularly in asm type code. But it is not so intuitive when spread over a page or more. It doesn't jump out and say "this is a loop"...syzygy wrote:Code: Select all
one_more_time: ... if (finished) goto done; ... goto one_more_time; done: ...
That is not so bad. I am beginning to think that my original approach while(1) {} might have been about the best that can be done, although it does require knowledge of C to realize that is an infinite while. Think I am going to revert to the while (1) and let it go...Ras wrote:Here you go:hgm wrote:I would prefer 'for(EVER)' or 'while(UNBROKEN)'.Code: Select all
#define EVER ;; ... for(EVER) { do_stuff(); }
I did not reply earlier because I was not well enough to work on my code. Today I commented out the statements that set the globals to zero and it is as you said. However, I have a question. In my C primer which I admit was written more than 20 years ago it says that global variables should be initialized to zero or otherwise they may be undefined in some implementations of C. Is that so archaic that I should no longer take that into consideration or leave it in because it doesn't hurt. Or maybe leave them in but commented out just in case?Fulvio wrote:https://stackoverflow.com/questions/160 ... -zero-in-c
Code: Select all
void Initialize() { s32 i, fs120, ts120, fs64, ts64; s32 dir[8] = {9, 11, -9, -11, 1, 10, -1, -10}; s32 din[8] = {8, 12, 19, 21, -8, -12, -19, -21}; s32 isOnBoard[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 (fs64 = 63; fs64 >= 0; fs64--) { fs120 = SQUARE120(fs64); for (i = 0; i < 8; i++) { ts120 = fs120 + din[i]; if (isOnBoard[ts120]) { dirKn[fs64] |= BIT64(SQUARE64(ts120)); } } for (i = 0; i < 8; i++) { ts120 = fs120 + dir[i]; if (isOnBoard[ts120]) { dirKi[fs64] |= BIT64(SQUARE64(ts120)); do { dirPtr[i][fs64] |= BIT64(SQUARE64(ts120)); ts120 += dir[i]; } while (isOnBoard[ts120]); } } } }