What is the use of conditional operator in while loop?
What is the use of conditional operator in while loop?
An MBA in finance imparts and improves management aptitude, inventive ability, critical thinking ability, and so forth. It offers a real-time experience that fabricates a staunch career foundation for students and working professionals. It helps them to thoroughly understand the financial sector.
Ravi Vishwakarma
16-Nov-2021A Loop is used to execute a block of code again and again for a certain number of times. for example, you can use a loop to print the first N natural numbers. A conditional control structure ( if-else, switch, conditional operator) allows us to execute a set of instructions in one scenario and another set of instructions in a different scenario.
A conditional operator ( also called a “Ternary Operator” ) functions in the same way as an if-else statement.
The syntax looks like this (condition to be tested) ? statement1 : statement2 ;
When the condition to be tested evaluates to True, statement 1 is executed.
Else statement 2 is executed.
Its the same as…
I hope this made the point clear !!