How to skip a block in Java?

breakpoints, for-loop, java, loops

Solution

You can use the keyword `continue` in order to accomplish what you are trying to do.

However you can also inverse your conditional test and use `count++` only if it is different (`!=` instead of `==` in your if) and do nothing otherwise

Problem

In the program given I have to make sure that if two consequtive characters are the same. I shouldn't increase the value of the variable (Count)... I have tried "break;", but that skips me out of the "for loop" which is very counter-productive. How can I skip the given part and still continue the "for loop"? Currently my output for "Hello//world" is 3. It should be 2 (the '/' indicates a ' '(Space)). Code ``` import java.util.Scanner; class CountWordsWithEmergency { public static void main() { Scanner input = new Scanner(System.in); System.out.println("Please input the String"); String inp = input.nextLine(); System.out.println("thank you"); int i = inp.length(); int count = 1; for(int j=0;j<=i-1;j++) //This is the for loop I would like to stay in. { char check = inp.charAt(j); if(check==' ') { if((inp.charAt(j+1))==check) //This is the condition to prevent increase for //count variable. { count = count; //This does not work and neither does break; } count++; } } System.out.println("The number of words are : "+count); } } ```

Original source