So i was practicing on past google code jam problems(btw it is on 7th april if you don't already know) and i wrote this code in which i put multiple if statements. Looks something like this:
for(int b=0;b<length;b++)
{
if(array[b]==1 && done1==false)
{
done1=true;
}
if(array[b]==2 && done2==false)
{
done2=true;
}
if(array[b]==3 && done3==false)
{
done3=true;
}
if(array[b]==4 && done4==false)
{
done4=true;
}
if(array[b]==5 && done5==false)
{
done5=true;
}
if(array[b]==6 && done6==false)
{
done6=true;
}
if(array[b]==7 && done7==false)
{
done7=true;
}
if(array[b]==8 && done8==false)
{
done8=true;
}
if(array[b]==9 && done9==false)
{
done9=true;
}
if(array[b]==0 && done0==false)
{
done0=true;
}
if(done0==true && done1==true && done2==true && done3==true && done4==true && done5==true && done6==true && done7==true && done8==true && done9==true)
{
System.out.println("Case"+" "+"#"+(K-T) + ":"+G);
break;
}
}
My question is does it check every 'if' statement or only till the first 'if' which satisfies the condition.Also is it bad if i write if statements like this? Any help is appreciated.Sorry if this is way too noob a question for you
Do let me know if you need more details.Thanks!
EDIT: Everyone seems to have the impression that i need the program to get out of the loop once the condition is fulfilled. I don't. I want it to check every condition and act accordingly. For context: there is a number N and i need to check if N,2N,3N.... contains all the digits and print the last number which will complete the set of digits.So I separate the digits and put them in an array and check with the for loop
.
Lastly I'm sorry for not debugging. I'm a beginner and i thought I'd just ask the pros.
Aucun commentaire:
Enregistrer un commentaire