You need to sign in to do that
Don't have an account?
Pavani Akella 9
Output of the code:
Integer i=1,counter=2;
do{
System.debug(i);
i++;
counter++;
}while(i==20&&counter==21);
What would be the output of the code?
Thanks in advance!
do{
System.debug(i);
i++;
counter++;
}while(i==20&&counter==21);
What would be the output of the code?
Thanks in advance!
The output of your code will be 1.
The loop will be executed for the first time(that's how do-while loops are designed to work) producing output 1. Then the condition gets checked and a false is returned. And the loop execution stops.
All Answers
The output of your code will be 1.
The loop will be executed for the first time(that's how do-while loops are designed to work) producing output 1. Then the condition gets checked and a false is returned. And the loop execution stops.
The output for integer will be 1 and the counter will be 2.
+1 for Narender..
Do-while runs at least once even if the condition is false because the condition is evaluated, after the execution of the body of loop.
For example, in the above code while the condition is not being satisfied and the output is 1 and 2. if you try to modify the code as follow
The above logic will return the integer output 2 and 3 and the counter will be 4.
--
Thanks,
Prashant