Continue Statement
Lesson 11 of 11 in Coddy's Control Statements in Java course.
Now, if you want to display details of five students with roll numbers, say 1, 2, 3, 4, and 5, and you only want to display details of students with odd roll numbers, you can use the continue statement.
The continue statement in Java terminates one iteration of a loop by skipping the instructions after it and begins with the next iteration, i.e., "continue" allows you to skip specific iterations of a loop without completely halting it.
When you use a continue statement in a loop, the current flow of the program skips the further implementation and iterates the next iteration of the loop.
Syntax:
continue;Challenge
EasyWrite a program that loops through a string and continues if encounters a space character, so space will be ignored. all other characters will be printed.
Try it yourself
class ContinueString {
public static void continueString(String s) {
// Write code here
}
}All lessons in Control Statements in Java
1What are Control Statements?
Introduction2Decision Making Statments
Simple if Statementif-else Statementif-else-if StatementNested if-StatementSwitch Case Statement