In a program, when manipulating and presenting data in a comprehensive format, you might have to take decision based on some condition. Depending on the result of the condition, you decide to select one of the values over the other.
Conditional operator is yet another operator supported in many programming languages. Various languages different variations of this operator. We will cover these variations in the videos related to these languages. Irrespective to the programming language, the conditional operator requires three operands and therefore, is also known as ternary operator. The most commonly used ternary operator uses the ?: symbol. The first operand is a condition while the second and third operands are some values. When used, it takes the form as:
Variable = condition ? value 1 : value 2
In this case, based on the evaluation of the condition, the operator assigns one of the two values separated by the : symbol. If the condition evaluates to true, value 1 is assigned to the variable, else value 2 is assigned to the variable.
After checking a condition, if you need to further check another condition, then you can use another conditional operator on the either sides of the : symbol. As a result, after the first condition is evaluated, the condition in the next conditional operator is evaluated based on the result of the first condition.
Using a conditional operator within a conditional operator is known as nesting. Depending on your requirements you can further use conditional operator at another level. However, you must consider that more you use nesting for the conditional operator, greater are the elements of confusion.
На этой странице сайта вы можете посмотреть видео онлайн Programming Basics – Using Operators in Pseudocodes: Part 3 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Let's Simplify Computers with MrigVats Learning 01 Январь 1970, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 4,683 раз и оно понравилось 99 зрителям. Приятного просмотра!