While Loop

The while statement

The while provides a mechanism for repeating C statements wiles a condition is true. In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.


Syntax -


while (condition){
program statement;

}

Example -

/* Sample program including the while loop */

#include

int main(void)
{

int loop = 0;

while (loop <=10)
{
printf(“%d”, loop);
++loop
}

return 0;

}

Output

0
1

10

No comments: