While Keyword


In C programming, the 'while' keyword is used to create a while loop.

The while loop is a control flow structure that repeatedly executes a block of code as long as a specified condition is true.

Here's an example of using the 'while' keyword to create a while loop:


int count = 1;
while (count <= 5) {
  printf("Count: %d\n", count);
  count++;
}

    

In this example, the while loop is created using the 'while' keyword. The condition 'count <= 5' is evaluated before each iteration.

If the condition is true, the block of code within the loop is executed.

The loop continues to execute as long as the condition remains true.

In this case, the loop prints the value of 'count' and increments it until 'count' becomes greater than 5.

The 'while' loop is useful when you want to repeat a block of code an indefinite number of times as long as a condition is met.

It allows for flexibility in controlling the flow of execution based on the condition.

Loading...

Search