As discussed before, loop contains three part Intialization Condition Checking Incrementation Or Decrementation do…while loop is also called exit control loop, it means that the statement of loop are always executed once even if the condition is false. In this while is ended by semicolon(;). Syntax variable=0; do { //statement variable++; or variable--; //increment or decrement }while(condition); Example is given below #include<stdio.h> #include<conio.h> void main() { int i = 10; // declaration and initialization at the same time clrscr(); do // do contains the actual code and the updation { printf("i = %d\n",i); i = i-1; // updation }while(i >…
-
-
As we discussed before the loop have three parts. Initialization Condition Checking Increment Or Decrement Part while loop is known as entry control loop, in this if the condition is true then the statement inside loop will be executed. Syntax variable=0; while(condition) { code statement variable++; or variable--; //increment or decrement part } Example is below #include<stdio.h> #include<conio.h> void main() { int i = 0; // declaration and initialization at the same time clrscr(); printf("\nPrinting numbers using while loop from 0 to 9\n\n"); /* while i is less than 10 */ while(i<10) { printf("%d\n",i); i++; // same as i=i+1; }…
-
for loop consists of three parts in a sequence. Initialization: Use to initialize the loop variable. Condition: It is checked after each iteration as an entry point to the loop. Increment or Decrement: Incrementing or Decrementing the loop variable to eventually terminate the loop not satisfying the loop condition. Remember that the loop condition checks the conditional statement before it loops again. Syntax: for(initialization, condition, incrementation or decrementation) { code statements; } Example is give below #include<stdio.h> #include<conio.h> void main() { //Always declare the variables before using them int i = 0; // declaration and initialization at the same time…