[Solved] How can i use if-else condition inside for loop?


Here’s a pseudo-code for you

count = 1
begin for : 
    if(condition)
        increment count by 1
        // do something...
        if (increment > 5)
            // do something...
            break //or return
    else
        // do something...
        break //or return
end of for

EDIT: Use break in your else block. The break statement breaks out of the closest loop.

for (int c = 0; c<ff.size(); c++) {
    if(mStreet.getText().toString().equals(ff.get(c).name)) {
        mActivity.finishActivityWithResult(mCurrentId);
    }
    else {
        Toast.makeText(mActivity, "Delivery Address not match", Toast.LENGTH_SHORT).show();
        break; // this will terminate your loop
    }
}

4

solved How can i use if-else condition inside for loop?