Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java Example – Usage of the continue keyword

Java Examples - continue Keyword Usage

Java Examples Java Examples

The Java continue statement is used to end the current iteration and move on to the next one, i.e. only this iteration ends, not all loops; subsequent iterations still proceed.

The following example uses the continue keyword to skip the current iteration and start the next one:

Main.java File

public

class

Main

{

public

static

void

main

(

String

[

]

args

)

{

StringBuffer

searchstr

=

new

StringBuffer

(

"

hello how are you.

"

)

;

int

length

=

searchstr

.

length

(

)

;

int

count

=

0

;

for

(

int

i

=

0

;

i

<

length

;

i

++

)

{

if

(

searchstr

.

charAt

(

i

)

!=

'

h

'

)

continue

;

count

++;

searchstr

.

setCharAt

(

i

,

'

h

'

)

;

}

System

.

out

.

println

(

"

Found

"

count

"

h characters

"

)

;

System

.

out

.

println

(

searchstr

)

;

}

}

The output of the above code is:


发现 2 个 h 字符
hello how are you.

Java Examples Java Examples