java continue keyword :-
- we can use continue keyword inside loops to skip current iteration and continue for the next iteration.
example:-
for(int i=0 ; i<10 ; i++)
{
if(i%2==0)
continue;
System.out.println(i);
}
Output is:
1
3
5
7
9
- We can use continue statement only inside a loop is we are using anywhere else, we will get compile time error saying "continue outside of loop".
example:-
class Test
{
public static void main(String [] args)
{
int x=10;
if(x==10)
continue;
System.out.println("Hello");
}
}
Compile Time Error: continue outside of loop
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home