From the course: Grasshopper and Rhino: C# Scripting

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Conditionals

Conditionals

From the course: Grasshopper and Rhino: C# Scripting

Start my 1-month free trial

Conditionals

- [Man] When scripting in C#, we often have the need to control the flow of our code, that is, execute different paths based on different conditions. Think of this like arriving at a t-junction in your car. You have either one of two choices, go left or go right. We can make decisions like these in C# using conditional statements "if" and "else". If you don't already, go ahead and open up the exercise file for this lesson. In here, you can see that I've already created a point and inputted it into the C# component using the variable point. Let's go ahead and open up this C# component. An if statement is used to check if a Boolean or Boolean expression is true or false, and then execute a piece of code based on the result. Let's create our first if statement to check if the Z property of the incoming point is above five. To create an if statement, the syntax starts with if, followed with open round brackets, and then the…

Contents