今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Conditionals
- [Instructor] To demonstrate Go conditional statements, we'll work with a function that is designed to take in a slice of ints and return two slices of ints representing the odd and even numbers. We'll use a for-range loop to iterate over the incoming slice. We'll use for and range over the ints. Since we don't care about the index in this particular example, we're using what's called a blank identifier to effectively discard the index that's coming back from calling the range keyword. Inside of the loop, we're setting up an inline variable right inside of the if statement, and we're going to use the module operator to determine if the number is even, and we interrogate the even boolean. And then now we'll add the value to the even slice. Note that this even slice is pre-declared as part of name return on line nine. Right here. Both odds and evens are pre-declared name returns. While we're here, we'll add an…