0

[SOLVED] Little confusion on while/ do while loop in C.

Here in my code, I tried to place the increment operator inside printf() to reduce the lines of code by removing the { braces. int i = 201; while(i <= 300) printf("%d\t", i, i++); And. i = 201; do printf("%d\t", i, i++); while(i <= 300); Is this a valid way to do and how does this work?

6th Nov 2020, 3:18 AM
Bibek Oli
Bibek Oli - avatar
2 Answers
+ 7
Try this printf("%d\t",i++); it will print current value and increment as your need
6th Nov 2020, 3:56 AM
AzhagesanăƒŸ(✿)
AzhagesanăƒŸ(✿) - avatar
+ 9
Why don't you try it on your own on code playground to see wether it is valid or not👇 https://code.sololearn.com/cfIc95OkbhvM/?ref=app { Warnings are generated because you are passing more than required arguments to printf() frunction. To get rid of that use method suggested by AzhagesanăƒŸ(˙❄˙) }
6th Nov 2020, 3:57 AM
Arsenic
Arsenic - avatar