Jordan Frampton
Jordan Frampton

Reputation: 1

is there a way to start a for loop again if your condition != null in java

As the title.. is this possible? For example:

for(blah blah blah){
code omitted
}
if(variable != null){
go back to start of for;
}

Upvotes: 0

Views: 310

Answers (1)

David
David

Reputation: 218930

Sure, just use a loop:

while (variable != null) {
    for(blah blah blah){
        code omitted
    }
}

That's the preferred control structure for repeating something while a condition exists. In this case the condition is variable != null.

Upvotes: 3

Related Questions