Which of the following structure is correct for WHILE loop?
Question
Which of the following structure is correct for WHILE loop?
Solution
The correct structure for a WHILE loop in most programming languages is:
while (condition) {
// code to be executed
}
Here's how it works:
- The
whilekeyword starts the loop. - The condition for the loop is specified in parentheses. This condition is checked before each iteration of the loop. If the condition is true, the loop will continue; if it's false, the loop will end.
- The code to be executed in each iteration of the loop is enclosed in curly braces
{}.
Here's an example in JavaScript:
let i = 0;
while (i < 5) {
console.log(i);
i++;
}
This code will print the numbers 0 through 4 to the console. The loop continues as long as i is less than 5.
Similar Questions
What type of iteration is used in While Loop
WHICH OF THE FOLLOWING IS NOT AN EXAMPLE A LOOP IN C LANGUAGE Question 1Answera.FOR b.DO WHILE c.IF d.WHILE
What is the primary difference between a while loop and a for loop
Which of the following is correct syntax for a while loop?Answer areawhile x = 5:while x == 5while (x == 5):while x == 5:
Which of the following loops will execute the statements at least once, even though the condition is false initially?Question 10Answera.forb.whilec.do whiled.all of the above
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.