PDA

View Full Version : Nested IF problem


java_hates_me
02-17-04, 04:08 PM
Hello ppl

I really need some help I'm new to java as it is but I'm teaching myself bit by bit and I'm writing a program that can do searches now I got it to work and everything but i want to change it into a nested IF statement and I believe that nested IF's are an IF within an IF but I cant fathom out how to convert the code I had before into a nested IF now so example of this would be appreciated.

thanks

this is the code I did to perform a search within an array, its also what I'm trying to convert to nested IF's..

//================================

for (int row=0;row<Firstname.length;row++){

if (options==1)
{
if (Cycle[row].equals("Yes"))
{
System.out.println(Firstname[row]+" "+Surname[row]+" "+Cycle[row]);

}
}
}

for (int row=0;row<Smoker.length;row++){

if (options==2)
{
if (Smoker[row].equals("Yes"))
{
System.out.println(Firstname[row]+" "+Surname[row]+" "+Smoker[row]);

}
}
}

//================================

stdunbar
02-17-04, 07:07 PM
How about something like:

if ((options==1) && (Cycle[row].equals("Yes"))
System.out.println(Firstname[row]+" "+Surname[row]+" "+Cycle[row]);

And remember, Java hates no one but it is not too fond of Microsoft people :)



Hello ppl

I really need some help I'm new to java as it is but I'm teaching myself bit by bit and I'm writing a program that can do searches now I got it to work and everything but i want to change it into a nested IF statement and I believe that nested IF's are an IF within an IF but I cant fathom out how to convert the code I had before into a nested IF now so example of this would be appreciated.

thanks

this is the code I did to perform a search within an array, its also what I'm trying to convert to nested IF's..

//================================

for (int row=0;row<Firstname.length;row++){

if (options==1)
{
if (Cycle[row].equals("Yes"))
{
System.out.println(Firstname[row]+" "+Surname[row]+" "+Cycle[row]);

}
}
}

for (int row=0;row<Smoker.length;row++){

if (options==2)
{
if (Smoker[row].equals("Yes"))
{
System.out.println(Firstname[row]+" "+Surname[row]+" "+Smoker[row]);

}
}
}

//================================