Seems that you have task to generate all k-coordinate cortages where k beetwen 0(inclusive) and 256(exclusive) and check them with your function isCap().
I advice you to write two function: increment cortage:
inc([0,0,0,0,0]) = [0,0,0,0,1]
or inc([12,13,15,5,255]) = [12,13,15,6,0]
and check function test if cortage is maximal. In your case :
boolean isCortageMaximum(a){
return a == [255,255,255,255,255];
}
and then your loop would be following:
while(!isCortageMaximum(a)){
if(isCap(a){
//your actions here
}
inc(a);
}