Hi there!
I came across a problem regarding loops.
For some reason, I want to check if there are double entries in my int array (rather String but nvm).
I came up with some kind of a solution, but I deeply hope there is a smarter way to do so:
String[] num = {"1", "1", "2", "3", "4", "5", "1", "8", "9", "9"};
int rand;
void setup() {
size(400, 400);
for (int i=0; i < 10; i++) {
rand=(int)random(1, 4);
num[i]=str(rand);
}
printArray(num);
dublette();
}
void draw() {
}
void dublette() {
int i=0;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
if (num[i].equals( num[i+3]) ) {
num[i+3]="XXX";
}
if (num[i].equals( num[i+4]) ) {
num[i+4]="XXX";
}
if ( num[i].equals( num[i+5]) ) {
num[i+5]="XXX";
}
if (num[i].equals( num[i+6]) ) {
num[i+6]="XXX";
}
if (num[i].equals( num[i+7]) ) {
num[i+7]="XXX";
}
if (num[i].equals( num[i+8]) ) {
num[i+8]="XXX";
}
if (num[i].equals( num[i+9]) ) {
num[i+9]="XXX";
}
i=1;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
if (num[i].equals( num[i+3]) ) {
num[i+3]="XXX";
}
if (num[i].equals( num[i+4]) ) {
num[i+4]="XXX";
}
if ( num[i].equals( num[i+5]) ) {
num[i+5]="XXX";
}
if (num[i].equals( num[i+6]) ) {
num[i+6]="XXX";
}
if (num[i].equals( num[i+7]) ) {
num[i+7]="XXX";
}
if (num[i].equals( num[i+8]) ) {
num[i+8]="XXX";
}
i=2;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
if (num[i].equals( num[i+3]) ) {
num[i+3]="XXX";
}
if (num[i].equals( num[i+4]) ) {
num[i+4]="XXX";
}
if ( num[i].equals( num[i+5]) ) {
num[i+5]="XXX";
}
if (num[i].equals( num[i+6]) ) {
num[i+6]="XXX";
}
if (num[i].equals( num[i+7]) ) {
num[i+7]="XXX";
}
i=3;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
if (num[i].equals( num[i+3]) ) {
num[i+3]="XXX";
}
if (num[i].equals( num[i+4]) ) {
num[i+4]="XXX";
}
if ( num[i].equals( num[i+5]) ) {
num[i+5]="XXX";
}
if (num[i].equals( num[i+6]) ) {
num[i+6]="XXX";
}
i=4;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
if (num[i].equals( num[i+3]) ) {
num[i+3]="XXX";
}
if (num[i].equals( num[i+4]) ) {
num[i+4]="XXX";
}
if ( num[i].equals( num[i+5]) ) {
num[i+5]="XXX";
}
i=5;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
if (num[i].equals( num[i+3]) ) {
num[i+3]="XXX";
}
if (num[i].equals( num[i+4]) ) {
num[i+4]="XXX";
}
i=6;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
if (num[i].equals( num[i+3]) ) {
num[i+3]="XXX";
}
i=7;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
if (num[i].equals( num[i+2]) ) {
num[i+2]="XXX";
}
i=8;
if (num[i].equals( num[i+1])) {
num[i+1]="XXX";
}
println("cleaned:");
printArray(num);
}
Because overall I’d like to check much bigger arrays for double entries ^^.
Could someone pleeease push me into a direction of applying this by (maybe even one single) loop(s)?
Because when I tried one big statement (if this || that || this…) I wasn’t able to replace that particular value.