Computer Science, asked by divyanshi261, 1 year ago

Question =>

Define For Loop, While Loop and do-while loop along with syntax and flowchart

# Computer Science.

Thanks ●ツ●

Answers

Answered by nain31
9
☜☆☞ıllıllı[ ANSWER ]ıllıllı☜☆☞

➡FOR LOOP

✔ITS A ENTRY CONTROLLED LOOP WHICH WILL FIRSTLY CHECK THE CONDITION THEN WILL EXECUTE. IF THE CONDITION IS FALSE LOOP WILL NOT EXECUTE EVEN ONCE
ITS A LOOP WHICH WORKS WITH FIXED NUMBER OF ILLETRATION AND THE INITIALIZATION, UPDATION AND CONDITION ARE GATHERED .

SYNTAX:-
for(initilization;condition;updation)
{
statements
}

EXAMPLE :--

for(i=1;i<=10;i++)
{
System. out.println(a);
}

➡WHILE LOOP..

✔ITS A ENTRY CONTROLLED LOOP WHICH WILL FIRSTLY CHECK THE CONDITION THEN WILL EXECUTE. IF THE CONDITION IS FALSE LOOP WILL NOT EXECUTE EVEN ONCE.ITS THE LOOP WHICH WORKS TILL THE CONDITION WILL NOT BE TRUE.
THE CONDITION, UPDATING AND INITIALIZATION IS SCATTERED .

SYNTAX:-

initialization
while(condition)
{
updating;
}

EXAMPLE:-

m=10;
while(m>0)
{
m=m-1;
}

➡DO WHILE LOOP.

✔ITS AN EXIT CONTROLLED LOOP WHICH WILL FIRST EXECUTE AND THEN WHILE CHECK THE CONDITION .IT WILL EXCEUTE ONCE EVEN IF THE CONDITION IS FALSE. IN THIS THE INITIALIZATION, UPDATION AND CONDITION ARE SCATTERED.

SYNTAX:--

initialization
do
{
updation
}while (condition);

EXAMPLE :--

m=10;
do
{
m=m-1;
}while(m>1);

✌✌⚛⚛HOPE IT HELPS⚛⚛ ✌✌✌

divyanshi261: Superb ❤niCELY exPLAINED❤Thanka ❤
divyanshi261: No worries
Anonymous: #αωєѕσмє ρѕу¢нσgιяℓ
Answered by janmayjaisolanki78
4
In most computer programming languages, a do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block.
The do while construct consists of a process symbol and a condition. First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false. Because do while loops check the condition after the block is executed, the control structure is often also known as a post-test loop. Contrast with the while loop, which tests the condition before the code within the block is executed, the do-while loop is an exit-condition loop. This means that the code must always be executed first and then the expression or test condition is evaluated. If it is true, the code executes the body of the loop again. This process is repeated as long as the expression evaluates to true. If the expression is false, the loop terminates and control transfers to the statement following the do-while loop. In other words, whereas a while loop sets the truth of a statement as a condition precedent for the code's execution, a do-while loop provides for the action's ongoing execution subject to defeasance by the condition's falsity, which falsity (i.e., the truth of the condition's negation) is set as a condition subsequent.
It is possible, and in some cases desirable, for the condition to always evaluate to true, creating an infinite loop. When such a loop is created intentionally, there is usually another control structure (such as a break statement) that allows termination of the loop.
Some languages may use a different naming convention for this type of loop. For example, the Pascal language has a "repeat until" loop, which continues to run until the control expression is true (and then terminates) — whereas a "while" loop runs while the control expression is true (and terminates once the expression becomes false).


"PLZ DO REPLY"
Attachments:
Similar questions