Home > database >  notes
notes

Time:10-06

While statement - when circulation, first determine conditions, after the execution of the loop body statements, loop body at least perform zero grammar while (expression)//attention here, there can be no semicolon statements; Execution: first to determine whether the value of the expression is true (established), if it is true, execute the statement, and then continue to determine the value of the expression to expression is false, while loop end note: expressions for any legitimate expression, for the loop execution conditions, namely the loop condition statements for any legitimate a statement (multiple statements, must add parentheses), and the statement is executed repeatedly, namely the loop body statement, in order to allow circulation to end, usually in the loop body statements have to loop condition is not established statements int x=8;//loop variable initialization while (x<10) {printf (" % d ", x); X++;//x to loop variable, by changing the value of the variable cycle, cycle will ultimately end//+ + x;//x=x + 1; } case 1-100 and # include "stdio.h" void main () {int sum=0, I=1; While (i<=100) {sum +=I; i++; } printf (" % d \ n ", sum); Printf (" % d % d ", sizeof (int), sizeof (long)); } 2, the do... While loop: until the circulation loop body to perform at least one grammar do} {statements while (expression);//note here must have a semicolon: execute a statement first, and then determine whether the expression, if formed, continue to execute the statement, otherwise end the do.. The while loop note: statement which is the loop body expressions for the loop condition when the loop condition (expression) initiative to true, can be unconditional and while loop transformation case 1-100 and int I=1, sum=0; Do {sum +=I; i++; } while (i<=100); Printf (" % d ", sum);

CodePudding user response:

Please note sent to personal blog, thank you