Putting a composite statement in the condition of a for loop

前端 未结 6 1083
一整个雨季
一整个雨季 2021-01-18 18:02

I have a contrived example to demonstrate the request for a specific functionality - I wonder if anyone has a clever trick to do this.

The following is a problem one

6条回答
  •  醉梦人生
    2021-01-18 18:56

    I have used the following type of construct for this situation. It is not more efficient (still has a condition at each iteration), but I like it because it results in a single printf:

    char *sep = " ";
    for(ii=0; ii<4; ii++) {
      if ( ii == 3 )
        sep = "\n";
      printf( "%d%s", ii, sep );
    }
    

提交回复
热议问题