Access Millions of academic & study documents

A) Discuss when do you use a continue statement Provide an example

Content type
User Generated
Showing Page:
1/2
A) Discuss when do you use a continue statement?
Provide an example.
Solution
The continue keyword can be used in loops. It causes the
loop to immediately jump to the next iteration of the loop.it
skips the execution of statements inside loops body for
the current iteration
Example
Sample.java
public class Sample {
public static void main(String args[]) {
int [] items = {1, 2, 3, 4, 5};
for(int i : items ) {
if( i == 3 ) {
continue;
}
System.out.print( i+\" \" );
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
A) Discuss when do you use a continue statement? Provide an example. Solution The continue keyword can be used in loops. It causes the loop to immediately jump to the next iteration of the loop.it skips the execution of statements inside loop’s body for the current iteration Example Sample.java public class Sample { public static void main(String args[]) { int [] items = {1, 2, 3, 4, 5}; for(int i : items ) { if( i == 3 ) { continue; } System.out.print( i+\" \" ); } } } output 1 2 4 5 use of continue in while loop syntax for using continue label output continue is used in loops to jumps ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4