All Questions
7 questions
-5
votes
1
answer
1k
views
How do I manage multiple nested for-loops without using multiple variables?
If I have code that looks like this:
int i;
void functionA (){
for (i=0; i<10; i++){
functionB();
}
}
void functionB (){
for (i=0; i<20; i++){
doSomething();
}
}
...
-2
votes
1
answer
283
views
For loop and recursion for a new shell in C [closed]
I code a new shell in C, that could be done in several ways: Flex/bison, finite state machine, abstract syntax tree or just a tokenizer in C. Now I've written a for-loop that changes the condition of ...
1
vote
3
answers
386
views
Use of for loop conditional statement unrelated to iterating variable
Is it considered decent form to write code like this:
int done = 0;
for (x = 0; !done; x++) {
... something involving 'x', that might end early ...
if (!(x < max))
done = 1;
}
...
3
votes
2
answers
7k
views
Infinite while loop CPU usage
I'm coding an script in C, which is going to check constantly an array of events, the idea is to check if the Date and time of certain event is equal to de current time and trigger something, i'm ...
0
votes
1
answer
1k
views
comparison of an unsigned variable to 0
When I execute the following loop :
unsigned m;
for( m = 10; m >= 0; --m ){
printf("%d\n",m);
}
the loop doesn't stop at m==0, it keeps executing interminably, so I thought that ...
6
votes
3
answers
709
views
Is doing two things on one line always a bad practice?
int *itPins = pins;
for(int i = 0; i < count; i++)
{
ConfigureGpifPinAsGpioOutput(itPins);
itPins++;
}
I have the impression that doing two things in one line is bad practice. This is why ...
0
votes
10
answers
1k
views
Why does the instruction "do" require a "while"? [closed]
Since this statement is so common:
while (true) (Java)
or
while (1) (C)
or sometimes
for (;;)
Why is there not a single instruction for this? I could think that an instruction that could do it ...