Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is while?

–3 votes
asked Jul 28, 2020 by Adrian (250 points)

2 Answers

+3 votes
answered Jul 28, 2020 by Peter Minarik (15,580 points)
edited Jul 28, 2020 by Peter Minarik

In most modern programming langues, there is a variant of while.

while is a keyword to create a loop, where generally the syntax is something like this:

while ([condition])
    [expression]

Which is to say, that as long as [condition] evaluates to true, [expression] (or the body of the loop) is kept executed over and over again.

The following C code counts backwards before a rocket is launched.

#include <stdio.h>

int main()
{
    printf("Rocket is launched in...\n");
    
    int seconds = 5;
    while (seconds > 0)
    {
        printf("%d...\n", seconds);
        seconds--;
    }
    printf("Ignition!\n");

    return 0;
}

The while loop terminates, when seconds will not be larger than zero anymore.

0 votes
answered Aug 4, 2020 by Amar Kulkarni (180 points)
while is an iterative control statement that is used to run a piece of code in a loop / n times.

syntax :

while(condition)
{
///statements;
}

-> mainly used when the programmer doesn't know how many times to run a code/statements
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...