Template For Assessments: Youtube
Template For Assessments: Youtube
Template For Assessments: Youtube
The Java _______ statement executes What is the main difference between a What is the output of the below Java
one statement from multiple conditions. WHILE and a DO-WHILE loop in Java? program with FOR loop?
for(int j=0; j<5;j++;)
System.out.print(j + ",");
c) do while(condition) c) exit c) 6
{
//statements
}
d) while(condition) d) continue d) 1 2 3 4 5
{
//statements
} do
Which of these An Enhanced FOR loop in public class temp Initialization, public class demo
selection statements Java misses ___ and __ { Increment/Decrement {
test only for equality? compared to the old- public static void public static void
style FOR loop. main(String agrs[]) main(String[] args)
{ {
for(int i=1; i<=10; i++); for(int i = 0; i<5; i++)
System.out.print(i); {
}
} System.out.println("He
llo");
break;
}
}
}
Analyse the output of
above code.
Recall/ Remembering Understanding Application Understanding Application
Ans: < switch > Ans: < Initialization, Ans: <Error > Ans: < > Ans: < Hello>
Increment/Decrement >
Assessment Type: Practice Worksheets: End of LO: in LMS/ downloadable PDF
BASIS OF
WHILE LOOP DO-WHILE LOOP
COMPARISON
The main feature of the while loop is that The main feature of the do while is an exit
Main Feature
it’s an entry controlled loop. controlled loop.
Given that the condition is checked first, Given that the condition is checked later,
Statements statements may or may not get the body statements will execute at least
executed. once.
The iterations do not occur if the In Do-while loop the iteration occurs at least
Iterations condition at the first iteration appears once even if the condition is false at the first
false. iteration.
Semicolon Semicolon (;) is not used in while loop. Semicolon (;) is used in Do-while loop.
In while loop, the controlling condition In Do-while loop the controlling condition
Controlling Condition
appears at the start of the loop. appears at the end of the loop.
The code is short and therefore it takes The code is relatively long and therefore it
Nature
much less time to execute. takes extra time to execute.