WHILE Loop in C Language:
(1) The while statement executes a block of code repeatedly as long as the control condition of the loop is true. The control condition of the while loop is executed before any statement inside the loop is executed.
(2) Sample C language code and its output, as shown:
#include <stdio.h> #include <conio.h> //Table of 2 using for loop int main() { int x; inti; i = 0; x = 1; while (x <= 10) { i = i + 2; printf(“2 * %d = %d \n”,x,i); x++; } getch(); return 0; } |
(3) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.
(4) After building the code, press the “Run” button, as shown.
(5) After pressing the “run” button, the output screen is opened, as shown.
while Loop Syntax:
while (condition) { //write logic } |