What is the “continue” keyword and how does it work in Java?

前端 未结 13 1784
温柔的废话
温柔的废话 2020-11-22 11:34

I saw this keyword for the first time and I was wondering if someone could explain to me what it does.

  • What is the continue keyword?
  • How
13条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 11:46

    Let's see an example:

    int sum = 0;
    for(int i = 1; i <= 100 ; i++){
        if(i % 2 == 0)
             continue;
        sum += i;
    }
    

    This would get the sum of only odd numbers from 1 to 100.

提交回复
热议问题