Find the output
void main()
{
do
{
System.out.println("FRIENDS");
while (true);
}
pls dont spam pls answer
Answers
There will be no Output as the program has Syntax Error...
Rectified Program:
void main()
{
do
{
System.out.println("FRIENDS");
}
while (true);
}
Output of the rectified program:
FRIENDS
FRIENDS
FRIENDS
and this will go on and will never stop until and unless it is forcefully stopped.
Answer:-
Error i.e no output
Explanation :-
The program will not execute
why?
As there is a syntax error
.°. There will be no output
First of all let's review Syntax of do-while loop:-
do
{
//{} can be omitted if there is only one Statement
-----------------
Statements
-----------------
//in this inside the loop only we have to update the value if required
}
wlile(test condition)
so as we can see here condition will be checked outside the loop i.e after currely brackes/paranthese({})
So correct snippet will be:-
void main()
{
do
{
System.out.println("FRIENDS");
}
while (true);
Output:
FRIENDS
FRIENDS
FRIENDS
FRIENDS
FRIENDS
...
...
...
The execution will not stop until and unless external internation occurs and such types of loops are known as infinite loop.