Help If Then Else

I am trying to make a function that tests two lists if the values of the first list are greater, equal, or less than the second list and output a chosen string. The native If node only has two outputs (true/false), this requires a third output.

So far I have this, but it only outputs one value, where I need each item in the list to be compared.

image

Longer explication of my goal: Trying to compare what the script has calculated as the required number of plumbing fixtures for the space to how many fixtures are placed in the model and create a color-coded filled region for each fixture type if the count is under, equal, or higher.

Hi @thebert,

Welcome to the Dynamo community.
I don’t think it’s required to create a function for this task. You can simply use nested if in a code block as below:

image

Placed>Clac?"_Solid Black":
	Placed==Clac?"_Solid White":
		"_Solid Red";

The syntax for if in DesignScript is condition ? value if True : value if False

3 Likes

As @AmolShah mentioned, you don’t need to go the Imperative route.
Though it can be done, when taking an imperative approach, you’ll need to think iteratively

pl;
cl;
[Imperative]
{
	a = [];
	for (i in (0..(List.Count(pl)-1)))
	{
		if (pl[i] > cl[i])
		{
			a[i] = "_Solid Black";
		}
		elseif (pl[i] == cl[i])
		{
			a[i] = "_Solid White";
		}
		else
		{
			a[i] = "_Solid Red";
		}
	}
	return a;
};
3 Likes

@AmolShah I had something close to this early on. I think I used a different operator for the nested statement, and was getting an error about having the same input within itself? I wasn’t sure if the order and/or which item was nested mattered, it seems it does matter.

1 Like

I suspected it was comparing the entire list instead of the individual values, but didn’t know how to change it.