Computer Science, asked by bsreelekha1711, 1 year ago

write the syntax of fo-while loop​

Answers

Answered by smartbrainz
0

do  

{  

statement(s);  

}  

while

( condition );

Explanation:

  • The 'do-while loop' checks the status of the condition at the loop end. This means that the 'loop body statements' will be 'performed at least once' even though the 'condition is never true'.
  • The 'conditional expression' appears at the 'end of the loop', so the 'statement(s) in the loop' will be executed once before the condition is evaluated. If the 'condition is true', the flow of the control will jump back and 'execute the statement'(s) in the 'loop again'.

To know more

How many times does the while loop get executed if the following function is called as f(190,15)?

f(m,n) {

ans := 1

while (m - n >= 0) {

ans := ans * 2

m := m - n

}

return(ans)

}

https://brainly.in/question/5603939

What is the similarity between while and do while loop in java

https://brainly.in/question/6038401

Answered by poojan
0

Syntax of do-while loop:

do

{

Statement 1;

Statement 2;

....

Statement n;

Update statement (Incrementation / decrementation);

} while(condition);

Explanation :

  • 'do-while loop' is a exit control loop.

  • On first iteration, the loop is executed once without checking the condition. So, this loop will run for once for sure, irrespective of the condition.

  • Once the 1st  iteration is completed, the condition will be checked, and thereafter, the loop will be executed based on the what condition returns. If true, loop continues, else, terminates.

Example:

#include <stdio.h>

int main ()

{

int i = 0;                             //initializing the variable

do                                      //do-while loop

{

    printf('hi');

    i++;                                 //incrementing operation

} while( i <= 5);

return 0;

}

Output :

hi

hi

hi

hi

hi

As i is assigned initially with zero, and do-while has a condition of i<=5, the loop runs till the increment reaches 5, i.e, for 5 times, resulting 5 'hi's in the by the print statement overall.

Learn more :

1) What is a loop?

https://brainly.in/question/607496

2) Difference between while loop and do-while loop.

https://brainly.in/question/6825169

Similar questions