---
title: "What is the use of conditional operator in while loop?"  
description: "What is the use of conditional operator in while loop?"  
author: "Mukul Goenka"  
published: 2021-11-15  
updated: 2021-11-15  
canonical: https://www.mindstick.com/forum/156837/what-is-the-use-of-conditional-operator-in-while-loop  
category: "c#"  
tags: ["c#", ".net", "java"]  
reading_time: 1 minute  

---

# What is the use of conditional operator in while loop?

What is the use of [conditional operator](https://www.mindstick.com/forum/23210/does-python-have-a-ternary-conditional-operator) in [while loop](https://www.mindstick.com/forum/34579/while-loop-in-python)?

## Replies

### Reply by Ravi Vishwakarma

A **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](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server)) 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…

```
if( condition )       statement1 ;
else  statement2 ;
```

I hope this made the point clear !!


---

Original Source: https://www.mindstick.com/forum/156837/what-is-the-use-of-conditional-operator-in-while-loop

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
