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