I want to make the for loop execute the code in the beginning. However, my beginning state is same as my ending state. Is there any way I can execute the code without writing it before the loop?
for(int i = queue1->front;
i%queue1->size != queue1->front;
i++) {
//some code
}
In the code, I am using a circular array and I want to print that using a loop.
Aside from using a do-while-loop you could use a flag to enter the loop in any case like this:
int first = 1;
for (int i = queue1->front; i%queue1->size != queue1->front || first; i++){
first = 0;
//some code
}
You can even integrate it directly into the for loop header, if you like:
for (int i = queue1->front, f=1; i%queue1->size != queue1->front || f; i++, f=0) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With