current position:Home>The problem of C language do while loop

The problem of C language do while loop

2022-02-02 21:04:11 CSDN Q & A

#include<stdio.h>main()int i=20,n=0;do{    n++;    switch(i%4)    {  case 0: i=i-7; break;       case 1:       case 2:       case 3: i++; break;    }}while(i>0);printf("%d",n);}

Compiled by computer is 17, I'd like to know that I've got i The value is 4 When , At that time n The value of should not be 15 Do you , The value is 4 In time case0 The calculation for the -3, Exit loop , Go straight into while Judge true or false The result is a false output 15, I don't know why it's equal to 17 n++ It's not taking values first and then +1 Do you




Refer to the answer 1:

1,2,3 Can make i++




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022104097784.html

Random recommended