From the course: Grasshopper and Rhino: C# Scripting
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Commenting2m 27s
-
(Locked)
Variables5m 1s
-
(Locked)
Numbers6m 36s
-
(Locked)
Strings5m 37s
-
(Locked)
Collections5m 34s
-
(Locked)
Arrays5m 32s
-
(Locked)
Comparing with operators5m 3s
-
(Locked)
Conditionals3m 30s
-
(Locked)
Logical operators6m 26s
-
(Locked)
Looping with the for loop5m 23s
-
(Locked)
Foreach looping4m 29s
-
(Locked)
Nested loops5m 12s
-
(Locked)
Methods6m 5s
-
(Locked)
Reference vs. value types5m 21s
-
(Locked)
Try and catch4m 14s
-
(Locked)
-
-