I was searching for “How to give multiple conditions in a for loop?” But there are no direct answers given.
After some research I found the correct way. Conditions should not be comma(,) or semicolon(;) separated. We can use the && operator to join both the conditions together.
for( initialization ; condition1 && condition2 ; increment)
Example:
for(int j= 0; j < 6 && j < ((int)abc[j] & 0xff) ; j++ )
{
//
}
Hope this helps the new Java developers.
You can also use “or” operator,