Shares
print sharing button Print
twitter sharing button Tweet
facebook sharing button Share
whatsapp sharing button Share
pinterest sharing button Pin
email sharing button Email
reddit sharing button Share
snapchat sharing button Snap
arrow_left sharing button
arrow_right sharing button

C/C++ Programming - while loop - Syntax and Example

<<Previous

Next >>





The syntax of while loop

while(expression)
  statement;

       (or)

while(expression)
{
  statements;
}

Here, first the expression is evaluated. If the conditional expression is true, statements inside the while loop will be executed after which the expression is reevaluated. This process continues until the conditional expression is false. When the condition is false, the while loop will be terminated.



Example C Program using while loop

#include<stdio.h>

int main()
{
  int b = 0;

  while(b <= 5)
  {
    printf("The value of b = %d\n",b);
    b++ ;
  }

  printf("The final value of b = %d\n",b);

  return(0);

}

When you compile and execute the above program, then you will get the following output:



<< Previous

Next >>




strcat() - String Concatenation        strcmp() - String Compare


strcpy() - String Copy        strlen() - String Length














C/C++ Programming - while loop - Syntax and Example

<<Previous

Next >>





The syntax of while loop

while(expression)
  statement;

       (or)

while(expression)
{
  statements;
}

Here, first the expression is evaluated. If the conditional expression is true, statements inside the while loop will be executed after which the expression is reevaluated. This process continues until the conditional expression is false. When the condition is false, the while loop will be terminated.



Example C Program using while loop

#include<stdio.h>

int main()
{
  int b = 0;

  while(b <= 5)
  {
    printf("The value of b = %d\n",b);
    b++ ;
  }

  printf("The final value of b = %d\n",b);

  return(0);

}

When you compile and execute the above program, then you will get the following output:



<< Previous

Next >>






strncat() - String n Concatenation        strlwr() - String Lower       

strncmp() - String n Compare       strncpy() - String n Copy