Next: Conditional Branches , Up: Conditional Expression   [ Contents ][ Index ]

8.4.1 Rules for the Conditional Operator

The first operand, condition , should be a value that can be compared with zero—a number or a pointer. If it is true (nonzero), then the conditional expression computes iftrue and its value becomes the value of the conditional expression. Otherwise the conditional expression computes iffalse and its value becomes the value of the conditional expression. The conditional expression always computes just one of iftrue and iffalse , never both of them.

Here’s an example: the absolute value of a number x can be written as (x >= 0 ? x : -x) .

Warning: The conditional expression operators have rather low syntactic precedence. Except when the conditional expression is used as an argument in a function call, write parentheses around it. For clarity, always write parentheses around it if it extends across more than one line.

Assignment operators and the comma operator (see Comma Operator ) have lower precedence than conditional expression operators, so write parentheses around those when they appear inside a conditional expression. See Order of Execution .

If Statement in C – How to use If-Else Statements in the C Programming Language

Dionysia Lemonaki

In the C programming language, you have the ability to control the flow of a program.

In particular, the program is able to make decisions on what it should do next. And those decisions are based on the state of certain pre-defined conditions you set.

The program will decide what the next steps should be based on whether the conditions are met or not.

The act of doing one thing if a particular condition is met and a different thing if that particular condition is not met is called control flow .

For example, you may want to perform an action under only a specific condition. And you may want to perform another action under an entirely different condition. Or, you may want to perform another, completely different action when that specific condition you set is not met.

To be able to do all of the above, and control the flow of a program, you will need to use an if statement.

In this article, you will learn all about the if statement – its syntax and examples of how to use it so you can understand how it works.

You will also learn about the if else statement – that is the else statement that is added to the if statement for additional program flexibility.

In addition, you will learn about the else if statement for when you want to add more choices to your conditions.

Here is what we will cover:

  • How to create an if statement in C
  • What is an example of an if statement?
  • What is an example of an if else statement?
  • What is an example of an else if statement?

What Is An if Statement In C?

An if statement is also known as a conditional statement and is used for decision-making. It acts as a fork in the road or a branch.

A conditional statement takes a specific action based on the result of a check or comparison that takes place.

So, all in all, the if statement makes a decision based on a condition.

The condition is a Boolean expression. A Boolean expression can only be one of two values – true or false.

If the given condition evaluates to true only then is the code inside the if block executed.

If the given condition evaluates to false , the code inside the if block is ignored and skipped.

How To Create An if statement In C – A Syntax Breakdown For Beginners

The general syntax for an if statement in C is the following:

Let's break it down:

  • You start an if statement using the if keyword.
  • Inside parentheses, you include a condition that needs checking and evaluating, which is always a Boolean expression. This condition will only evaluate as either true or false .
  • The if block is denoted by a set of curly braces, {} .
  • Inside the if block, there are lines of code – make sure the code is indented so it is easier to read.

What Is An Example Of An if Statement?

Next, let’s see a practical example of an if statement.

I will create a variable named age that will hold an integer value.

I will then prompt the user to enter their age and store the answer in the variable age .

Then, I will create a condition that checks whether the value contained in the variable age is less than 18.

If so, I want a message printed to the console letting the user know that to proceed, the user should be at least 18 years of age.

I compile the code using gcc conditionals.c , where gcc is the name of the C compiler and conditionals.c is the name of the file containing the C source code.

Then, to run the code I type ./a.out .

When asked for my age I enter 16 and get the following output:

The condition ( age < 18 ) evaluates to true so the code in the if block executes.

Then, I re-compile and re-run the program.

This time, when asked for my age, I enter 28 and get the following output:

Well... There is no output.

This is because the condition evaluates to false and therefore the body of the if block is skipped.

I have also not specified what should happen in the case that the user's age is greater than 18.

I could write another if statement that will print a message to the console if the user's age is greater than 18 so the code is a bit clearer:

I compile and run the code, and when prompted for my age I enter again 28:

This code works. That said, there is a better way to write it and you will see how to do that in the following section.

What Is An if else Statement in C?

Multiple if statements on their own are not helpful – especially as the programs grow larger and larger.

So, for that reason, an if statement is accompanied by an else statement.

The if else statement essentially means that " if this condition is true do the following thing, else do this thing instead".

If the condition inside the parentheses evaluates to true , the code inside the if block will execute. However, if that condition evaluates to false , the code inside the else block will execute.

The else keyword is the solution for when the if condition is false and the code inside the if block doesn't run. It provides an alternative.

The general syntax looks something like the following:

What Is An Example Of An if else Statement?

Now, let's revisit the example with the two separate if statements from earlier on:

Let's re-write it using an if else statement instead:

If the condition is true the code in the if block runs:

If the condition is false the code in the if block is skipped and the code in the else block runs instead:

What Is An else if Statement?

But what happens when you want to have more than one condition to choose from?

If you wish to chose between more than one option and want to have a greater variety in actions, then you can introduce an else if statement.

An else if statement essentially means that "If this condition is true, do the following. If it isn't, do this instead. However, if none of the above is true and all else fails, finally do this."

What Is An Example Of An else if Statement?

Let's see how an else if statement works.

Say you have the following example:

If the first if statement is true, the rest of the block will not run:

If the first if statement is false, then the program moves on to the next condition.

If that is true the code inside the else if block executes and the rest of the block doesn't run:

If both of the previous conditions are all false, then the last resort is the else block which is the one to execute:

And there you have it – you now know the basics of if , if else , and else if statements in C!

I hope you found this article helpful.

To learn more about the C programming language, check out the following free resources:

  • C Programming Tutorial for Beginners
  • What is The C Programming Language? A Tutorial for Beginners
  • The C Beginner's Handbook: Learn C Programming Language basics in just a few hours

Thank you so much for reading and happy coding :)

Read more posts .

If this article was helpful, share it .

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Guru99

C Conditional Statement: IF, IF Else and Nested IF Else with Example

Barbara Thompson

What is a Conditional Statement in C?

Conditional Statements in C programming are used to make decisions based on the conditions. Conditional statements execute sequentially when there is no condition around the statements. If you put some condition for a block of statements, the execution flow may change based on the result evaluated by the condition. This process is called decision making in ‘C.’

In ‘C’ programming conditional statements are possible with the help of the following two constructs:

1. If statement

2. If-else statement

It is also called as branching as a program decides which statement to execute based on the result of the evaluated condition.

If statement

The condition evaluates to either true or false. True is always a non-zero value, and false is a value that contains zero. Instructions can be a single instruction or a code block enclosed by curly braces { }.

Following program illustrates the use of if construct in ‘C’ programming:

The above program illustrates the use of if construct to check equality of two numbers.

If Statement

  • In the above program, we have initialized two variables with num1, num2 with value as 1, 2 respectively.
  • Then, we have used if with a test-expression to check which number is the smallest and which number is the largest. We have used a relational expression in if construct. Since the value of num1 is smaller than num2, the condition will evaluate to true.
  • Thus it will print the statement inside the block of If. After that, the control will go outside of the block and program will be terminated with a successful result.

Relational Operators

C has six relational operators that can be used to formulate a Boolean expression for making a decision and testing conditions, which returns true or false :

< less than

<= less than or equal to

> greater than

>= greater than or equal to

== equal to

!= not equal to

Notice that the equal test (==) is different from the assignment operator (=) because it is one of the most common problems that a programmer faces by mixing them up.

For example:

Keep in mind that a condition that evaluates to a non-zero value is considered as true.

The If-Else statement

The If-Else Statement

The if-else is statement is an extended version of If. The general form of if-else is as follows:

n this type of a construct, if the value of test-expression is true, then the true block of statements will be executed. If the value of test-expression if false, then the false block of statements will be executed. In any case, after the execution, the control will be automatically transferred to the statements appearing outside the block of If.

Let’s start.

The If-Else Statement

  • We have initialized a variable with value 19. We have to find out whether the number is bigger or smaller than 10 using a ‘C’ program. To do this, we have used the if-else construct.
  • Here we have provided a condition num<10 because we have to compare our value with 10.
  • As you can see the first block is always a true block which means, if the value of test-expression is true then the first block which is If, will be executed.
  • The second block is an else block. This block contains the statements which will be executed if the value of the test-expression becomes false. In our program, the value of num is greater than ten hence the test-condition becomes false and else block is executed. Thus, our output will be from an else block which is “The value is greater than 10”. After the if-else, the program will terminate with a successful result.

In ‘C’ programming we can use multiple if-else constructs within each other which are referred to as nesting of if-else statements.

Conditional Expressions

There is another way to express an if-else statement is by introducing the ?: operator. In a conditional expression the ?: operator has only one statement associated with the if and the else.

Nested If-else Statements

When a series of decision is required, nested if-else is used. Nesting means using one if-else construct within another one.

Let’s write a program to illustrate the use of nested if-else.

The above program checks if a number is less or greater than 10 and prints the result using nested if-else construct.

Nested If-else Statements

  • Firstly, we have declared a variable num with value as 1. Then we have used if-else construct.
  • In the outer if-else, the condition provided checks if a number is less than 10. If the condition is true then and only then it will execute the inner loop . In this case, the condition is true hence the inner block is processed.
  • In the inner block, we again have a condition that checks if our variable contains the value 1 or not. When a condition is true, then it will process the If block otherwise it will process an else block. In this case, the condition is true hence the If a block is executed and the value is printed on the output screen.
  • The above program will print the value of a variable and exit with success.

Try changing the value of variable see how the program behaves.

NOTE: In nested if-else, we have to be careful with the indentation because multiple if-else constructs are involved in this process, so it becomes difficult to figure out individual constructs. Proper indentation makes it easy to read the program.

Nested Else-if statements

Nested else-if is used when multipath decisions are required.

The general syntax of how else-if ladders are constructed in ‘C’ programming is as follows:

This type of structure is known as the else-if ladder. This chain generally looks like a ladder hence it is also called as an else-if ladder. The test-expressions are evaluated from top to bottom. Whenever a true test-expression if found, statement associated with it is executed. When all the n test-expressions becomes false, then the default else statement is executed.

Let us see the actual working with the help of a program.

The above program prints the grade as per the marks scored in a test. We have used the else-if ladder construct in the above program.

Nested Else-if Statements

  • We have initialized a variable with marks. In the else-if ladder structure, we have provided various conditions.
  • The value from the variable marks will be compared with the first condition since it is true the statement associated with it will be printed on the output screen.
  • If the first test condition turns out false, then it is compared with the second condition.
  • This process will go on until the all expression is evaluated otherwise control will go out of the else-if ladder, and default statement will be printed.

Try modifying the value and notice the change in the output.

  • Decision making or branching statements are used to select one path based on the result of the evaluated expression.
  • It is also called as control statements because it controls the flow of execution of a program.
  • ‘C’ provides if, if-else constructs for decision-making statements.
  • We can also nest if-else within one another when multiple paths have to be tested.
  • The else-if ladder is used when we have to check various ways based upon the result of the expression.
  • Dynamic Memory Allocation in C using malloc(), calloc() Functions
  • Type Casting in C: Type Conversion, Implicit, Explicit with Example
  • C Programming Tutorial PDF for Beginners
  • 13 BEST C Programming Books for Beginners (2024 Update)
  • Difference Between C and Java
  • Difference Between Structure and Union in C
  • Top 100 C Programming Interview Questions and Answers (PDF)
  • calloc() Function in C Library with Program EXAMPLE

C Functions

C structures, c if ... else, conditions and if statements.

You have already learned that C supports the usual logical conditions from mathematics:

  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b
  • Equal to a == b
  • Not Equal to: a != b

You can use these conditions to perform different actions for different decisions.

C has the following conditional statements:

  • Use if to specify a block of code to be executed, if a specified condition is true
  • Use else to specify a block of code to be executed, if the same condition is false
  • Use else if to specify a new condition to test, if the first condition is false
  • Use switch to specify many alternative blocks of code to be executed

The if Statement

Use the if statement to specify a block of code to be executed if a condition is true .

Note that if is in lowercase letters. Uppercase letters (If or IF) will generate an error.

In the example below, we test two values to find out if 20 is greater than 18. If the condition is true , print some text:

We can also test variables:

Example explained

In the example above we use two variables, x and y , to test whether x is greater than y (using the > operator). As x is 20, and y is 18, and we know that 20 is greater than 18, we print to the screen that "x is greater than y".

C Exercises

Test yourself with exercises.

Print "Hello World" if x is greater than y .

Start the Exercise

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

cppreference.com

Assignment operators.

Assignment and compound assignment operators are binary operators that modify the variable to their left using the value to their right.

[ edit ] Simple assignment

The simple assignment operator expressions have the form

Assignment performs implicit conversion from the value of rhs to the type of lhs and then replaces the value in the object designated by lhs with the converted value of rhs .

Assignment also returns the same value as what was stored in lhs (so that expressions such as a = b = c are possible). The value category of the assignment operator is non-lvalue (so that expressions such as ( a = b ) = c are invalid).

rhs and lhs must satisfy one of the following:

  • both lhs and rhs have compatible struct or union type, or..
  • rhs must be implicitly convertible to lhs , which implies
  • both lhs and rhs have arithmetic types , in which case lhs may be volatile -qualified or atomic (since C11)
  • both lhs and rhs have pointer to compatible (ignoring qualifiers) types, or one of the pointers is a pointer to void, and the conversion would not add qualifiers to the pointed-to type. lhs may be volatile or restrict (since C99) -qualified or atomic (since C11) .
  • lhs is a (possibly qualified or atomic (since C11) ) pointer and rhs is a null pointer constant such as NULL or a nullptr_t value (since C23)

[ edit ] Notes

If rhs and lhs overlap in memory (e.g. they are members of the same union), the behavior is undefined unless the overlap is exact and the types are compatible .

Although arrays are not assignable, an array wrapped in a struct is assignable to another object of the same (or compatible) struct type.

The side effect of updating lhs is sequenced after the value computations, but not the side effects of lhs and rhs themselves and the evaluations of the operands are, as usual, unsequenced relative to each other (so the expressions such as i = ++ i ; are undefined)

Assignment strips extra range and precision from floating-point expressions (see FLT_EVAL_METHOD ).

In C++, assignment operators are lvalue expressions, not so in C.

[ edit ] Compound assignment

The compound assignment operator expressions have the form

The expression lhs @= rhs is exactly the same as lhs = lhs @ ( rhs ) , except that lhs is evaluated only once.

[ edit ] References

  • C17 standard (ISO/IEC 9899:2018):
  • 6.5.16 Assignment operators (p: 72-73)
  • C11 standard (ISO/IEC 9899:2011):
  • 6.5.16 Assignment operators (p: 101-104)
  • C99 standard (ISO/IEC 9899:1999):
  • 6.5.16 Assignment operators (p: 91-93)
  • C89/C90 standard (ISO/IEC 9899:1990):
  • 3.3.16 Assignment operators

[ edit ] See Also

Operator precedence

[ edit ] See also

  • Recent changes
  • Offline version
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link
  • Page information
  • In other languages
  • This page was last modified on 19 August 2022, at 08:36.
  • This page has been accessed 54,567 times.
  • Privacy policy
  • About cppreference.com
  • Disclaimers

Powered by MediaWiki

Extra Clang Tools 19.0.0git documentation

Clang-tidy - bugprone-assignment-in-if-condition.

«   bugprone-assert-side-effect   ::   Contents   ::   bugprone-bad-signal-to-kill-thread   »

bugprone-assignment-in-if-condition ¶

Finds assignments within conditions of if statements. Such assignments are bug-prone because they may have been intended as equality tests.

This check finds all assignments within if conditions, including ones that are not flagged by -Wparentheses due to an extra set of parentheses, and including assignments that call an overloaded operator=() . The identified assignments violate BARR group “Rule 8.2.c” .

C Data Types

C operators.

  • C Input and Output
  • C Control Flow
  • C Functions
  • C Preprocessors

C File Handling

  • C Cheatsheet

C Interview Questions

  • C Programming Language Tutorial
  • C Language Introduction
  • Features of C Programming Language
  • C Programming Language Standard
  • C Hello World Program
  • Compiling a C Program: Behind the Scenes
  • Tokens in C
  • Keywords in C

C Variables and Constants

  • C Variables
  • Constants in C
  • Const Qualifier in C
  • Different ways to declare variable as constant in C
  • Scope rules in C
  • Internal Linkage and External Linkage in C
  • Global Variables in C
  • Data Types in C
  • Literals in C
  • Escape Sequence in C
  • Integer Promotions in C
  • Character Arithmetic in C
  • Type Conversion in C

C Input/Output

  • Basic Input and Output in C
  • Format Specifiers in C
  • printf in C
  • Scansets in C
  • Formatted and Unformatted Input/Output functions in C with Examples
  • Operators in C
  • Arithmetic Operators in C
  • Unary operators in C
  • Relational Operators in C
  • Bitwise Operators in C
  • C Logical Operators

Assignment Operators in C

  • Increment and Decrement Operators in C
  • Conditional or Ternary Operator (?:) in C
  • sizeof operator in C
  • Operator Precedence and Associativity in C

C Control Statements Decision-Making

  • Decision Making in C (if , if..else, Nested if, if-else-if )
  • C - if Statement
  • C if...else Statement
  • C if else if ladder
  • Switch Statement in C
  • Using Range in switch Case in C
  • while loop in C
  • do...while Loop in C
  • For Versus While
  • Continue Statement in C
  • Break Statement in C
  • goto Statement in C
  • User-Defined Function in C
  • Parameter Passing Techniques in C
  • Function Prototype in C
  • How can I return multiple values from a function?
  • main Function in C
  • Implicit return type int in C
  • Callbacks in C
  • Nested functions in C
  • Variadic functions in C
  • _Noreturn function specifier in C
  • Predefined Identifier __func__ in C
  • C Library math.h Functions

C Arrays & Strings

  • Properties of Array in C
  • Multidimensional Arrays in C
  • Initialization of Multidimensional Array in C
  • Pass Array to Functions in C
  • How to pass a 2D array as a parameter in C?
  • What are the data types for which it is not possible to create an array?
  • How to pass an array by value in C ?
  • Strings in C
  • Array of Strings in C
  • What is the difference between single quoted and double quoted declaration of char array?
  • C String Functions
  • Pointer Arithmetics in C with Examples
  • C - Pointer to Pointer (Double Pointer)
  • Function Pointer in C
  • How to declare a pointer to a function?
  • Pointer to an Array | Array Pointer
  • Difference between constant pointer, pointers to constant, and constant pointers to constants
  • Pointer vs Array in C
  • Dangling, Void , Null and Wild Pointers in C
  • Near, Far and Huge Pointers in C
  • restrict keyword in C

C User-Defined Data Types

  • C Structures
  • dot (.) Operator in C
  • Structure Member Alignment, Padding and Data Packing
  • Flexible Array Members in a structure in C
  • Bit Fields in C
  • Difference Between Structure and Union in C
  • Anonymous Union and Structure in C
  • Enumeration (or enum) in C

C Storage Classes

  • Storage Classes in C
  • extern Keyword in C
  • Static Variables in C
  • Initialization of static variables in C
  • Static functions in C
  • Understanding "volatile" qualifier in C | Set 2 (Examples)
  • Understanding "register" keyword in C

C Memory Management

  • Memory Layout of C Programs
  • Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
  • Difference Between malloc() and calloc() with Examples
  • What is Memory Leak? How can we avoid?
  • Dynamic Array in C
  • How to dynamically allocate a 2D array in C?
  • Dynamically Growing Array in C

C Preprocessor

  • C Preprocessor Directives
  • How a Preprocessor works in C?
  • Header Files in C
  • What’s difference between header files "stdio.h" and "stdlib.h" ?
  • How to write your own header file in C?
  • Macros and its types in C
  • Interesting Facts about Macros and Preprocessors in C
  • # and ## Operators in C
  • How to print a variable name in C?
  • Multiline macros in C
  • Variable length arguments for Macros
  • Branch prediction macros in GCC
  • typedef versus #define in C
  • Difference between #define and const in C?
  • Basics of File Handling in C
  • C fopen() function with Examples
  • EOF, getc() and feof() in C
  • fgets() and gets() in C language
  • fseek() vs rewind() in C
  • What is return type of getchar(), fgetc() and getc() ?
  • Read/Write Structure From/to a File in C
  • C Program to print contents of file
  • C program to delete a file
  • C Program to merge contents of two files into a third file
  • What is the difference between printf, sprintf and fprintf?
  • Difference between getc(), getchar(), getch() and getche()

Miscellaneous

  • time.h header file in C with Examples
  • Input-output system calls in C | Create, Open, Close, Read, Write
  • Signals in C language
  • Program error signals
  • Socket Programming in C
  • _Generics Keyword in C
  • Multithreading in C
  • C Programming Interview Questions (2024)
  • Commonly Asked C Programming Interview Questions | Set 1
  • Commonly Asked C Programming Interview Questions | Set 2
  • Commonly Asked C Programming Interview Questions | Set 3

c assignment in if condition

Assignment operators are used for assigning value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. The value on the right side must be of the same data-type of the variable on the left side otherwise the compiler will raise an error.

Different types of assignment operators are shown below:

1. “=”: This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example:

2. “+=” : This operator is combination of ‘+’ and ‘=’ operators. This operator first adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example:

If initially value stored in a is 5. Then (a += 6) = 11.

3. “-=” This operator is combination of ‘-‘ and ‘=’ operators. This operator first subtracts the value on the right from the current value of the variable on left and then assigns the result to the variable on the left. Example:

If initially value stored in a is 8. Then (a -= 6) = 2.

4. “*=” This operator is combination of ‘*’ and ‘=’ operators. This operator first multiplies the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example:

If initially value stored in a is 5. Then (a *= 6) = 30.

5. “/=” This operator is combination of ‘/’ and ‘=’ operators. This operator first divides the current value of the variable on left by the value on the right and then assigns the result to the variable on the left. Example:

If initially value stored in a is 6. Then (a /= 2) = 3.

Below example illustrates the various Assignment Operators:

Please Login to comment...

Similar reads.

  • C-Operators
  • cpp-operator

advertisewithusBannerImg

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Codeforwin

If else programming exercises and solutions in C

if...else is a branching statement . It is used to take an action based on some condition. For example – if user inputs valid account number and pin, then allow money withdrawal.

If statement works like “If condition is met, then execute the task” . It is used to compare things and take some action based on the comparison. Relational and logical operators supports this comparison.

C language supports three variants of if statement.

  • Simple if statement
  • if…else and if…else…if statement
  • Nested if…else statement

As a programmer you must have a good control on program execution flow. In this exercise we will focus to control program flow using if...else statements.

Always feel free to drop your queries and suggestions below in the comments section . I will try to get back to you asap.

Required knowledge

Basic C programming , Relational operators , Logical operators

List of if...else programming exercises

  • Write a C program to find maximum between two numbers.
  • Write a C program to find maximum between three numbers.
  • Write a C program to check whether a number is negative, positive or zero.
  • Write a C program to check whether a number is divisible by 5 and 11 or not.
  • Write a C program to check whether a number is even or odd.
  • Write a C program to check whether a year is leap year or not.
  • Write a C program to check whether a character is alphabet or not.
  • Write a C program to input any alphabet and check whether it is vowel or consonant.
  • Write a C program to input any character and check whether it is alphabet, digit or special character.
  • Write a C program to check whether a character is uppercase or lowercase alphabet .
  • Write a C program to input week number and print week day .
  • Write a C program to input month number and print number of days in that month.
  • Write a C program to count total number of notes in given amount .
  • Write a C program to input angles of a triangle and check whether triangle is valid or not.
  • Write a C program to input all sides of a triangle and check whether triangle is valid or not.
  • Write a C program to check whether the triangle is equilateral, isosceles or scalene triangle.
  • Write a C program to find all roots of a quadratic equation .
  • Write a C program to calculate profit or loss.
  • Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >= 70% : Grade C Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F
  • Write a C program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95%
  • Write a C program to input electricity unit charges and calculate total electricity bill according to the given condition: For first 50 units Rs. 0.50/unit For next 100 units Rs. 0.75/unit For next 100 units Rs. 1.20/unit For unit above 250 Rs. 1.50/unit An additional surcharge of 20% is added to the bill

Learn C++ practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn c++ interactively, introduction to c++.

  • Getting Started With C++
  • Your First C++ Program

C++ Fundamentals

  • C++ Comments
  • C++ Variables, Literals and Constants
  • C++ Data Types
  • C++ Type Modifiers
  • C++ Constants
  • C++ Basic Input/Output
  • C++ Operators

Flow Control

  • C++ Relational and Logical Operators

C++ if, if...else and Nested if...else

  • C++ for Loop

C++ while and do...while Loop

C++ break Statement

C++ continue Statement

  • C++ switch..case Statement
  • C++ goto Statement

C++ Ternary Operator

  • C++ Functions
  • C++ User-defined Function Types
  • C++ Programming Default Arguments
  • C++ Function Overloading
  • C++ Inline Functions
  • C++ Recursion

Arrays and Strings

  • Passing Array to a Function in C++ Programming
  • C++ Multidimensional Arrays
  • C++ String Class

Pointers and References

  • C++ Pointers
  • C++ Pointers and Arrays
  • C++ References
  • C++ Pass by Reference
  • C++ Return by Reference
  • C++ Memory Management: new and delete

Structures and Enumerations

  • C++ Structures
  • C++ Structure and Function
  • C++ Pointers to Structure
  • C++ Enumeration

Object Oriented Programming I

  • C++ Classes and Objects
  • C++ Constructors and Destructors
  • C++ Access Modifiers
  • C++ Encapsulation
  • C++ Inheritance
  • C++ Public, Protected and Private Inheritance
  • C++ Multiple, Multilevel and Hierarchical Inheritance
  • C++ Pass and return object from C++ Functions
  • C++ friend Function and friend Classes
  • C++ Polymorphism
  • C++ Shadowing Base Class Member Function
  • C++ Virtual Functions and Function Overriding
  • C++ Abstract Class and Pure Virtual Function

OOP - Overloading

  • C++ Constructor Overloading
  • C++ Operator Overloading

Standard Template Library (STL) I

  • C++ Standard Template Library
  • C++ STL Containers
  • C++ std::array
  • C++ Vectors
  • C++ Forward List
  • C++ Priority Queue

Standard Template Library (STL) II

  • C++ Multimap
  • C++ Multiset
  • C++ Unordered Map
  • C++ Unordered Set
  • C++ Unordered Multiset
  • C++ Unordered Multimap

Standard Template Library (STL) III

  • C++ Iterators
  • C++ Algorithm
  • C++ Functor

Advanced Topics I

  • C++ Exceptions Handling
  • C++ File Handling
  • C++ Ranged for Loop
  • C++ Nested Loop
  • C++ Bitwise Operators
  • C++ Function Template
  • C++ Class Templates
  • C++ Type Conversion
  • C++ Type Conversion Operators

Advanced Topics II

  • C++ Namespaces
  • C++ Preprocessors and Macros
  • C++ Storage Class
  • C++ Buffers
  • C++ istream
  • C++ ostream

C++ Tutorials

  • Display Factors of a Number

In computer programming, we use the if...else statement to run one block of code under certain conditions and another block of code under different conditions.

For example, assigning grades (A, B, C) based on marks obtained by a student.

  • if the percentage is above 90 , assign grade A
  • if the percentage is above 75 , assign grade B
  • if the percentage is above 65 , assign grade C
  • C++ if Statement

The if statement evaluates the condition inside the parentheses ( ) .

  • If the condition evaluates to true , the code inside the body of if is executed.
  • If the condition evaluates to false , the code inside the body of if is skipped.

Note: The code inside { } is the body of the if statement.

How if Statement Works

Example 1: C++ if Statement

When the user enters 5 , the condition number > 0 is evaluated to true and the statement inside the body of if is executed.

When the user enters -5 , the condition number > 0 is evaluated to false and the statement inside the body of if is not executed.

  • C++ if...else

The if statement can have an optional else clause.

The if..else statement evaluates the condition inside the parenthesis.

How if...else Statement Works

If the condition evaluates true ,

  • the code inside the body of if is executed
  • the code inside the body of else is skipped from execution

If the condition evaluates false ,

  • the code inside the body of else is executed
  • the code inside the body of if is skipped from execution

Example 2: C++ if...else Statement

In the above program, we have the condition number >= 0 . If we enter the number greater or equal to 0 , then the condition evaluates true .

Here, we enter 4 . So, the condition is true . Hence, the statement inside the body of if is executed.

Here, we enter -4 . So, the condition is false . Hence, the statement inside the body of else is executed.

  • C++ if...else...else if statement

The if...else statement is used to execute a block of code among two alternatives. However, if we need to make a choice between more than two alternatives, we use the if...else if...else statement.

  • If condition1 evaluates to true , the code block 1 is executed.
  • If condition1 evaluates to false , then condition2 is evaluated.
  • If condition2 is true , the code block 2 is executed.
  • If condition2 is false , the code block 3 is executed.

How if...else if...else Statement Works

Note: There can be more than one else if statement but only one if and else statements.

Example 3: C++ if...else...else if

In this program, we take a number from the user. We then use the if...else if...else ladder to check whether the number is positive, negative, or zero.

If the number is greater than 0 , the code inside the if block is executed. If the number is less than 0 , the code inside the else if block is executed. Otherwise, the code inside the else block is executed.

  • C++ Nested if...else

Sometimes, we need to use an if statement inside another if statement. This is known as nested if statement.

Think of it as multiple layers of if statements. There is a first, outer if statement, and inside it is another, inner if statement.

  • We can add else and else if statements to the inner if statement as required.
  • The inner if statement can also be inserted inside the outer else or else if statements (if they exist).
  • We can nest multiple layers of if statements.

Example 4: C++ Nested if

In the above example,

  • We take an integer as an input from the user and store it in the variable num .
  • If true , then the inner if...else statement is executed.
  • If false , the code inside the outer else condition is executed, which prints "The number is 0 and it is neither positive nor negative."
  • If true , then we print a statement saying that the number is positive.
  • If false , we print that the number is negative.

Note: As you can see, nested if...else makes your logic complicated. If possible, you should always try to avoid nested if...else .

Body of if...else With Only One Statement

If the body of if...else has only one statement, you can omit { } in the program. For example, you can replace

The output of both programs will be the same.

Note: Although it's not necessary to use { } if the body of if...else has only one statement, using { } makes your code more readable.

  • More on Decision Making

The ternary operator is a concise, inline method used to execute one of two expressions based on a condition. To learn more, visit C++ Ternary Operator .

If we need to make a choice between more than one alternatives based on a given test condition, the switch statement can be used. To learn more, visit C++ switch .

  • C++ Program to Check Whether Number is Even or Odd
  • C++ Program to Check Whether a Character is Vowel or Consonant.
  • C++ Program to Find Largest Number Among Three Numbers

Table of Contents

  • Introduction

Sorry about that.

Related Tutorials

C++ Tutorial

  • International

live news

Trump hush money trial

live news

Israel-Hamas war

live news

Campus protests across the US

live news

Tornado risk in Central US

Hamas says it has accepted a ceasefire proposal

By Kathleen Magramo, Adam Renton, Antoinette Radford, Sana Noor Haq, Ed Upright and Aditi Sangal, CNN

Israel urges people to evacuate parts of eastern Rafah "immediately." Here's what we know

From CNN staff

A person holds a leaflet dropped over Rafah by Israeli military aircraft, ordering people in parts of eastern Rafah to evacuate, on May 6.

Israel’s military on Monday called on people in parts of eastern Rafah to   "evacuate immediately" to what it called a humanitarian area.

“For your safety, the Defense Army urges you to evacuate immediately to the expanded humanitarian area at the checkpoints,” IDF spokesperson Avichay Adraee said in a statement.

The call comes a day after the country’s defense minister told troops in Gaza to expect “intense action" in the city "in the near future.”

Despite warnings from the UN and aid groups, Israel has repeatedly signaled plans to send ground troops into Rafah, a southern city on the border with Egypt, where more than a million displaced Palestinians are believed to have taken refuge since October 7.

Catch up on the latest on the evacuation here:

  • Who's affected: The Israeli military told people to evacuate Rafah's Al-Shawka municipality and the neighborhoods of Al-Salam, Al-Jneina, Tiba Zaraa, and Al-Bayouk. The military said it was a “limited scope operation to temporarily evacuate” and “not wide-scale evacuation” and impacts about 100,000 people.
  • No IDF assurances: Israel’s constant bombardment of Gaza since October 7 has  devastated the besieged enclave , reducing whole neighborhoods to rubble and many of those seeking shelter in Rafah have been displaced multiple times. The IDF would not offer assurances that the area they would move to would not be shelled.
  • International warnings: Previous orders from Israel to evacuate parts of Gaza ahead of military operations have been criticized by the UN and humanitarian groups, which have repeatedly said there is no safe space in Gaza for people to flee to. A Rafah ground invasion "would mean more suffering and death" for displaced Palestinians, a spokesperson for the UN's humanitarian agency said.
  • Israeli signals: Israeli Defense Minister Yoav Galant told troops Sunday in Gaza to expect “intense action in Rafah in the near future, and in other places all over the strip,” because — as he put it — Hamas does not intend to reach an agreement on hostages and a ceasefire. A Hamas delegation left Egypt on Sunday after the latest round of talks, saying “in-depth and serious discussions took place.”
  • Border closure: The IDF's announcement came a day after Israel closed the Kerem Shalom border crossing to humanitarian trucks after it was hit by rockets. Three IDF soldiers were killed and three critically injured in the attack, which was claimed by Hamas’ military wing. It was not clear whether the call for evacuation was in response to the attack at Kerem Shalom, which has been central to  getting aid into Gaza .

This post was corrected to remove a quote erroneously attributed to an IDF spokesperson saying residents “have days at least to move.” The spokesperson did not give a timeline.

Israeli strikes kill at least 34, wound 25 across Gaza

From Journalist Khader Al Za’znoun, Abeer Salman and Mia Alberti

A woman mourns as she carries the shrouded body of a child killed following overnight Israeli strikes on Rafah on May 6.

Overnight Israeli strikes have killed at least 34 people and wounded 25 across Gaza, according to an update from local officials.

In the southern city of Rafah , 26 people were killed, including children and babies, when airstrikes targeted a residential area and hit 11 houses, according to the Civil Defence Directorate in Gaza.

"Our teams in Rafah are still dealing with multiple targeting of residential and uninhabited homes, resulting in dozens of deaths, injured, and others missing under the rubble," it said.

On Monday, Israel’s military urged residents in eastern Rafah to  "evacuate immediately," a day after the country's defense minister told troops in Gaza to expect "intense action" in the city "in the near future."

In Gaza City , two people were killed and five wounded after an airstrike hit an apartment building near the Samar intersection in the center of the city. The victims were sent to al-Ahli Baptist hospital, according to medical officials.

In Deir el-Balah , central Gaza, six people were killed and 20 wounded in an airstrike on a UN agency school in Nuseirat, the Al-Aqsa Martyrs Hospital told CNN. 

The Israeli military confirmed the attack on the United Nations Relief and Works Agency for Palestine Refugees (UNRWA) complex.

The military struck what it called a “Hamas command and control center” located in an UNRWA complex in central Gaza, it said in a statement.

“As a result of the strike, the Hamas’ command and control center located in the UNRWA complex is no longer operational,” it said.

The death toll has been updated in this post.

"The necessary conditions for survival are absent in Rafah," Doctors Without Borders report says

CNN's Ibrahim Dahman in Cairo and Zeena Saifi in Jerusalem 

Children queue to receive food aid from a charity organization in Rafah, on May 3.

The "necessary conditions for survival are absent" in the southern Gaza city of Rafah, as medical facilities have been stretched to the limit, according to a report from Medical NGO Medicins Sans Frontieres (Doctors Without Borders).

The devastation in Rafah extends "far beyond those killed by Israeli bombardments and airstrikes", saying that deaths as a result of the disruption to critical healthcare are "silent killings" that are "equally tragic."

It notes a "marked deterioration" in people's health, with rising rates of "acute malnutrition", medical facilities that are "inundated with patients and operating beyond their limits", and the current medical response "rendered ineffective by the Israeli authorities' siege". 

 "This crisis is entirely man-made; what is being witnessed is a situation of deliberate deprivation," MSF wrote in the report released on April 29.

The current situation could result in "tens of thousands of non-trauma-related" deaths that could happen in the next six months, even in the event of a ceasefire, the report said.

Malnutrition: Between January 2024 and the end of March 2024, MSF registered 216 cases of moderate and severe acute malnutrition in children under five at Al-Shaboura and Al-Mawasi primary healthcare centers in Rafah and 25 cases among pregnant women and new mothers.

These figures represent only a small part of the larger reality, as they are based on screening of patients coming to the primary healthcare centers, while many people in Rafah do not have access to MSF’s services," the report said. 

 "The more than one million Palestinian men, women and children who have risked everything to seek refuge in Rafah remain exposed to serious physical and mental harm, with no information about the future besides the confirmation of an imminent invasion of Rafah by the Israeli army," it added. 

About 100,000 people asked to evacuate parts of eastern Rafah, Israeli military says

From CNN's Kathleen Magramo

An Israeli soldier stands on a tank near the border with southern Gaza on May 5.

About 100,000 people in parts of eastern Rafah have been told to evacuate by the Israel Defense Forces, the military's international spokesperson Colonel Nadav Shoshani said during a briefing.

Israel has repeatedly signaled plans to send ground troops into Rafah, a southern city on the border with Egypt, where more than a million displaced Palestinians are believed to have taken refuge since October 7.

Aid agencies have also warned that the territory is facing a spiraling humanitarian crisis, with the director of the World Food Programme describing that Gaza is facing " a full blown famine ."

Evacuation from eastern Rafah "is a limited scale operation," IDF says

From CNN's Sandi Sidhu

The Israel Defense Forces say that evacuation of residents and displaced people in eastern Rafah is "not a wide-scale evacuation of Rafah this is a limited-scale operation in the area of Eastern Rafah." 

Colonel Nadav Shoshani, IDF's international spokesperson, said in a press briefing Monday they were "calling on people of Eastern Rafah to move north."

When asked about how long residents would have to leave, Shoshani said,

When asked by CNN about what the operational reason for the move is, Shoshani said, "It's part of our of our plans to dismantle Hamas, and as I said, we had a violent reminder of their presence and their operational abilities in Rafah yesterday and as part of our plans to dismantle from us and to bring back our hostages."

Shoshani would not be drawn about whether this evacuation was linked to an attack on IDF soldiers yesterday . "I don't want to go into specific of our operational ideas and plans and timing," he said.

Rafah concerns: Israeli Defense Minister Yoav Galant told troops Sunday morning in Gaza to expect “intense action in Rafah in the near future, and in other places all over the Strip,” because – as he put it — Hamas does not intend to reach an agreement on hostages and a ceasefire.

Aid agencies have been warning Israel about a full-scale ground invasion of Rafah

“Any ground operation would mean more suffering and death” for the 1.2 million displaced Palestinians sheltering in and around the Strip’s southernmost city, the United Nations Office for the Coordination of Humanitarian Affairs spokesperson Jens Laerke told journalists in Geneva.

Israeli military flyers tell eastern Rafah residents that remaining puts their lives in danger

From CNN's Mia Alberti and Kathleen Magramo

The Israel Defense Forces has dropped leaflets ordering residents to evacuate eastern Rafah.

The Israeli military has dropped flyers telling residents of eastern Rafah to evacuate temporarily toward what they called an expanded humanitarian area.

The flyers warned people in Rafah Camp, the Brazil Camp and the neighborhoods Al-Shabura and Al-Zohour to evacuate.

"The IDF is about to operate with force against the terror organizations in the area you currently reside, as the IDF has operated so far. Anyone in the area puts themselves and their family members in danger. For your safety, evacuate immediately to the expanded humanitarian area in Al-Mawasi," the flyers dropped in Rafah read.

Flyers were also dropped in other parts of Gaza, which said "Gaza City is a dangerous fighting zone; avoid crossing to the north of Wadi Gaza."

Israeli military tells Gazans in parts of eastern Rafah to evacuate

From CNN's Helen Regan, Sophie Jeong and Abeer Salman

A man sits amid rubble of a destroyed building following Israeli attacks on the al-Salam neighborhood of Rafah on May 5.

Israel’s military has issued a call for residents of eastern Rafah to   “evacuate immediately,”   a day after the country’s defense minister told troops inside Gaza to expect “intense action in Rafah in the near future.”

Avichay Adraee, head of the Arab media division of the IDF Spokesperson’s Unit, wrote, “For your safety, the Defense Army urges you to evacuate immediately to the expanded humanitarian area at the checkpoints.”

Adraee made “an urgent call” to people who were residing in “the municipality of Al-Shawka and in the neighborhoods - Al-Salam, Al-Jneina, Tiba Zaraa, and Al-Bayouk in the Rafah area.”

An IDF spokesperson said in a briefing Monday that it was a “limited scope operation to temporarily evacuate” and “not wide-scale evacuation.”

Israel has repeatedly signaled plans to send troops into Rafah, a southern city on the border with Egypt, where more than a million displaced Palestinians are believed to have taken refuge since October 7.

Israeli Defense Minister Yoav Galant told troops Sunday morning inside the Gaza Strip to expect “intense action in Rafah in the near future, and in other places all over the Strip,” because – as he put it — Hamas does not intend to reach an agreement on hostages and a ceasefire.

Read the full story.

Little sign of breakthrough in ceasefire and hostage talks as Israel and Hamas trade blame

From CNN's Ibrahim Dahman, Tim Lister, Michael Schwartz and Lauren Said-Moorhouse

Israel’s Prime Minister Benjamin Netanyahu has said he “cannot accept” Hamas’ demands to end the war in Gaza as the two sides traded blame amid fresh ceasefire talks that showed little sign of a breakthrough.

Discussions are thought to have centered around  a new framework , proposed by Cairo, that calls for the militant group to release hostages kidnapped from Israel in exchange for a pause in  hostilities in Gaza .

A Hamas delegation left Egypt on Sunday after the latest round of grueling months of talks, saying “in-depth and serious discussions took place.”

There had been some cause for optimism, with Egyptian media citing an Egyptian official as saying there had been “significant progress” in negotiations. But the latest comments from Israel and Hamas show how far apart the two remain.

On Sunday, Hamas’ political bureau leader Ismail Haniyeh said in a statement that the group was “still keen” to reach an agreement with mediators but that any proposal would have to guarantee Israeli withdrawal and cease fighting in the enclave permanently.

He reiterated that the delegation carried “positive and flexible positions” aimed at stopping “the aggression against our people, which is a fundamental and logical position that lays the foundation for a more stable future.”

Netanyahu in turn accused Hamas of making unacceptable demands in the Cairo talks, adding that Israel had “demonstrated a willingness to go a long way” in the negotiations.

He said Hamas’ demand that Israel withdraw from Gaza was out of the question.

“We are not ready to accept a situation in which the Hamas battalions come out of their bunkers, take control of Gaza again, rebuild their military infrastructure, and return to threatening the citizens of Israel in the surrounding settlements, in the cities of the south, in all parts of the country,” Netanyahu said.

What we know about the number of hostages still held in Gaza

From CNN’s Larry Register, Richard Greene and Tim Lister

A person walks by a wall of posters of hostages kidnapped by Hamas, in Tel Aviv, Israel, on May 6.

Israeli officials believe 128  hostages taken in the October 7 attacks  remain in Gaza, and that at least 34 of them are dead.

The Israel Defense Forces said Friday that the remains of Elyakim Libman, who had been classified as a hostage in Gaza, were found in Israeli territory.

Israel officially considers people to be hostages, even if they are dead, until their remains are returned. 

Not all the hostages are Israeli citizens. Eight are Thai and one is Nepali.

The total number of hostages provided by Israel's military has fluctuated in the months since the attack, based on its latest intelligence.

There are an additional four hostages, two of whom are dead, who have been held in Gaza since before October 7, according to the Israeli Prime Minister’s Office.

There is little sign of a breakthrough in hostage negotiations between Israel and Hamas, as the two sides traded blame in remarks over the weekend.

Please enable JavaScript for a better experience.

Brittney Griner reveals harsh Russian prison conditions, suicidal thoughts in Robin Roberts interview

Phoenix Mercury center Brittney Griner stands at attention during the national anthem before a WNBA basketball game against the Washington Mystics, Sunday, July 23, 2023, in Washington.

Brittney Griner, the WNBA star who spent nearly 10 months in a Russian prison two years ago, said she contemplated suicide in the early days of her detainment. 

“I did. I didn’t think I could get through what I needed to get through,” Griner said during a special ABC News report on 20/20 that aired Wednesday. She said considering how her loved ones would react to her death made her dismiss those thoughts and instead think, “I have to endure this.”

Griner, 33, a nine-time WNBA All-Star and two-time Olympic gold medalist, was stopped at a security checkpoint in February 2022. Two cartridges of cannabis oil, a legal substance in Arizona, where she lives and plays for the Phoenix Mercury, were found in her backpack when she landed in Russia, where possession of cannabis is a serious offense. She was issued drug-related charges and faced up to 10 years in a notorious penal colony.

During the hourlong interview with Robin Roberts, Griner occasionally became emotional as she described the fear that gripped her, details of the abhorrent conditions she faced and the frightening prospect of never returning to the United States, among other elements of her experience.

During the interview, Griner also read excerpts of her memoir, “Coming Home,” which recounts her detention in Russia and will be released Tuesday.

ABC's Robin Roberts interviews Brittney Griner.

Griner, like many WNBA athletes, plays overseas in the off-season. She was on a Russian team for the previous seven years because of the $1 million salary she earned — about five times more than she garnered in the WNBA.

She said she did not realize the cannabis, which she uses to manage pain, was in her luggage as she hastily packed her bag after waking up late. As she was headed to a connecting flight at the Moscow airport, she was stopped at a security checkpoint, where the cannabis oil was found. Griner equated the mistake to a person losing his car keys or misplacing his eyeglasses. But she offered no excuses.

Sitting across from Roberts with curly hair instead of the trademark locs she sported that extended to the small of her back, Griner said “I knew that” cannabis was illegal in Russia. “Honest to God,” she read from her book, “I just totally forgot the pen was in my bag.”

Realizing she had the cannabis was “like an elevator just dropped from under my feet,” she told Roberts. “My life is over right here. … How was I this absent-minded to make this huge mistake? I could visualize everything I worked for just crumbling.”

After the detainment, she described frantically texting her wife, Cherelle Griner, and her agent, seeking help. Eventually, she said she was detained at a notoriously harsh jail in a 7-foot-by-7-foot cell with a bed too small for her 6-foot-9-inch frame, a sink and a hole in the floor to be used as a toilet.

Griner said she ripped apart one of the few T-shirts she was allowed in her cell to use as a washcloth to instead use as “toilet paper.”

“I felt less than human,” she said.

A week later, Russia invaded Ukraine, and “I felt like I was never coming home.” 

It got worse, she said, when she was transferred to another harsh prison, Correctional Colony No. 1. She said her cell was “filth,” with “dirt and grime and a leaky sink. Blood stains.”

Breakfast there was porridge “that was more like cement” and dinner was “a little piece of fish full of bones,” she said. The mattress had a huge blood stain, Griner added. She was allowed one roll of toilet paper a month and for a few months, she said, “we didn’t get anything.” The toothpaste had expired 15 years earlier.

Brittney Griner arrives to a hearing at the Khimki Court

The toughest days, she added, came when she was left outside during the frigid Russian winter for up to two hours.

“I wanted to take my life more than once,” she said, reading from her book. “I felt like leaving here so badly.”

After 134 days, Griner went to trial. She pleaded guilty . “The guilty plea was to take ownership of what happened,” Griner said.

She was sentenced to nine years and sent to an even harsher penal colony . 

“I was just so scared because of so much unknown,” Griner said. She said the new place was frigid. She shared an open space with up to 60 women. There was one bathroom with three toilets, no hot water — and a long sink that everyone shared at the same time.

Her locs froze. Spiders were so rampant that they built a nest in her hair. So she cut it.

“I had to do what I had to do to survive,” she said.

All the while, her wife, WNBA family and fans kept her name and case on the front burner through various acts, including a social media campaign, moments of silence at games and calls to President Joe Biden. Griner was aware of the push and it was encouraging, but she said hearing so many complimentary things about herself made her feel like she “was watching my funeral.”

Finally, hope emerged that she could be released. The Biden administration wanted to have her and former U.S. Marine Paul Whelan, who had been detained in Russia since 2018, released in a trade for Russians imprisoned in the U.S. 

But Russia would not include Whelan, who it claims is a spy, in any deal. The U.S. has said Whelan has been wrongfully detained in Russia. On Dec. 8, 2022, after begrudgingly writing a letter of contrition to Russian President Vladimir Putin, Griner was released in a rare prisoner exchange for Russian arms dealer Viktor Bout, also known as the “Merchant of Death,” ending her traumatic ordeal. 

She said that if she had the power to make the exchange, she would have included “Paul and brought him home. … No one should be left behind.” 

While the harrowing experience is behind her, she said she still deals with racist and homophobic jeers, either in person or via social media. 

“It’s been going on for a while,” Griner said. “I try to forget. That used to work until I realized suppressing things is not the way to go. But I know who I am, and the village I have, the people around me, know who I am. And that’s enough for me.” 

She teared up when talking about the lingering impact of the arrest and prison stint. “I don’t think I’ve really gotten through it all the way,” Griner said. “I let everybody down. I try to give myself grace. People say I should give myself some grace. It’s just so hard for me to do that.”

If you or someone you know is in crisis, call or text 988 to reach the Suicide and Crisis Lifeline or chat live at 988lifeline.org . You can also visit SpeakingOfSuicide.com/resources for additional support.

For more from NBC BLK, sign up for our weekly newsletter .

c assignment in if condition

Curtis Bunn is an Atlanta-based journalist for NBC BLK who writes about race.

  • Election 2024
  • Entertainment
  • Newsletters
  • Photography
  • Personal Finance
  • AP Investigations
  • AP Buyline Personal Finance
  • AP Buyline Shopping
  • Press Releases
  • Israel-Hamas War
  • Russia-Ukraine War
  • Global elections
  • Asia Pacific
  • Latin America
  • Middle East
  • Election Results
  • Delegate Tracker
  • AP & Elections
  • Auto Racing
  • 2024 Paris Olympic Games
  • Movie reviews
  • Book reviews
  • Personal finance
  • Financial Markets
  • Business Highlights
  • Financial wellness
  • Artificial Intelligence
  • Social Media

Rangers’ Max Scherzer scratched from 2nd scheduled rehab start because of sore thumb

Texas Rangers pitcher Max Scherzer stands outside the dugout after the team's 7-1 win in a baseball game against the Washington Nationals in Arlington, Texas, Tuesday, April 30, 2024. (AP Photo/Tony Gutierrez)

Texas Rangers pitcher Max Scherzer stands outside the dugout after the team’s 7-1 win in a baseball game against the Washington Nationals in Arlington, Texas, Tuesday, April 30, 2024. (AP Photo/Tony Gutierrez)

Texas Rangers pitcher Max Scherzer watches from the dugout during the seventh inning of a baseball game against the Detroit Tigers, Tuesday, April 16, 2024, in Detroit. (AP Photo/Carlos Osorio)

FILE - Texas Rangers starter Max Scherzer throws during the first inning of Game 6 of the baseball team’s AL Championship Series against the Houston Astros, Oct. 23, 2023, in Houston. Scherzer says he has turned a corner in rehabilitation from back surgery and appears to be ahead of schedule on his return to the Rangers. The three-time Cy Young Award winner is coming off a 40-pitch bullpen session and is planning to throw live batting practice next week. (AP Photo/David J. Phillip, File)

  • Copy Link copied

ARLINGTON, Texas (AP) — Texas Rangers right-hander Max Scherzer was scratched from his second scheduled rehab start Tuesday because of thumb soreness.

The soreness is similar to what Scherzer experienced last year before being sidelined for the end of the regular season and the start of the playoffs for the World Series champion Rangers.

Scherzer is rehabbing from surgery in mid-December to repair a herniated disk in his lower back , and said that isn’t giving him any issues.

“I’m frustrated. You want to be out there pitching. I’ve put myself in a position to get back out there,” Scherzer said in the Rangers’ clubhouse. “Coming off the back surgery, I’ve jumped through every hoop and really been putting myself in position to help the team out sooner than anybody thought. And the reason I’m not going out there is a thumb injury.”

Texas manager Bruce Bochy classified it as a “minor setback” for the three-time Cy Young Award winner.

“You’re talking days, not weeks,” Bochy said.

The 39-year-old Scherzer had been scheduled to start for Double-A Frisco at Corpus Christi on Tuesday night. That was six days after the eight-time All-Star threw 52 pitches into the third inning of his first rehab start for Triple-A Round Rock.

Baltimore Orioles starting pitcher Kyle Bradish throws during the second inning of a baseball game against the New York Yankees, Thursday, May 2, 2024, in Baltimore. (AP Photo/Nick Wass)

Scherzer said the inside ligament on his right thumb bothered him some in a simulated game before that, but he was able to manage in the start for Round Rock. Things changed in the last few days while preparing to start another game.

“Coming out of the bullpen, it was just going to get worse. And then it was starting to leak into the forearm. The forearm was starting to get tight on me,” he said. “Just need a couple days to let everything breathe, get everything back underneath me. There’s nothing really structurally wrong. It’s just some discomfort and just need to let it subside so nothing bad happens.”

The Rangers acquired Scherzer from the Mets in a deadline trade last July after the pitcher agreed to opt in on the final year of his contract for this season at $43.3 million. New York is paying $30.83 million of that to Texas in twice-monthly installments.

After the trade, Scherzer was 4-2 with a 3.20 ERA in eight starts for the Rangers, the last in the regular season on Sept. 12 before being sidelined by a muscle strain in his shoulder . He returned to make two starts in the American League Championship Series, then Game 3 of the World Series before exiting after three innings because of his back.

Scherzer said Tuesday he had some thumb soreness in the regular season last year that became forearm tightness and led to the shoulder issue.

“That was the progression last year, and this was starting to mimic it,” he said.

As for the rehab of his back and how it was recovering, Scherzer said he had the kind of velocity he would have in spring training in the start for Round Rock. He said it was a normal ramp-up in an effort to get back into the Rangers’ rotation.

His 3,367 career strikeouts are the most among active pitchers, and he’s second on the active list with 214 wins and 448 games started.

“We’ll let this thing clear up a little,” Bochy said. “You have to expect these things, especially when a guy’s coming back from a pretty good layoff. The good news is it’s not his back. His thumb’s a little sore, and that will clear up.”

AP MLB: https://apnews.com/hub/MLB

c assignment in if condition

IMAGES

  1. If Statement in C Language

    c assignment in if condition

  2. C++ If...else (With Examples)

    c assignment in if condition

  3. If-else Statement in C

    c assignment in if condition

  4. C#

    c assignment in if condition

  5. Conditional Statements in C

    c assignment in if condition

  6. C++ PROGRAMMING ( USE OF IF, ELSE,ELIF)

    c assignment in if condition

VIDEO

  1. Decision Making & Conditional Statement in C Language Part

  2. if else statement in c language

  3. NPTEL Problem Solving through Programming in C ASSIGNMENT 6 ANSWERS 2024

  4. Assignment Operator in C Programming

  5. Part 19. Nested If-Else Statement in C++ Programming || Exit Exam Course

  6. Nptel introduction to programming in c assignment week 3 answer 2024| programming in c week 3 answer

COMMENTS

  1. When would you want to assign a variable in an if condition?

    Some compilers will generate warnings for suspicious assignments in a conditional expression, though you usually have to enable the warning explicitly. For example, in Visual C++, you have to enable C4706 (or level 4 warnings in general). I generally turn on as many warnings as I can and make the code more explicit in order to avoid false ...

  2. C

    The working of the if statement in C is as follows: STEP 1: When the program control comes to the if statement, the test expression is evaluated. STEP 2A: If the condition is true, the statements inside the if block are executed. STEP 2B: If the expression is false, the statements inside the if body are not executed. STEP 3: Program control moves out of the if block and the code after the if ...

  3. If...Else Statement in C Explained

    Conditional code flow is the ability to change the way a piece of code behaves based on certain conditions. In such situations you can use if statements.. The if statement is also known as a decision making statement, as it makes a decision on the basis of a given condition or expression. The block of code inside the if statement is executed is the condition evaluates to true.

  4. Conditional Rules (GNU C Language Manual)

    8.4.1 Rules for the Conditional Operator. The first operand, condition, should be a value that can be compared with zero—a number or a pointer.If it is true (nonzero), then the conditional expression computes iftrue and its value becomes the value of the conditional expression. Otherwise the conditional expression computes iffalse and its value becomes the value of the conditional expression.

  5. If Statement in C

    The if else statement essentially means that " if this condition is true do the following thing, else do this thing instead". If the condition inside the parentheses evaluates to true, the code inside the if block will execute. However, if that condition evaluates to false, the code inside the else block will execute.

  6. Can we put assignment operator in if condition?

    zeeshan. 13 Answers. Answer. + 8. Yes you can put assignment operator (=) inside if conditional statement (C/C++) and its boolean type will be always evaluated to true since it will generate side effect to variables inside in it. And if you use equality relational operator (==) then its boolean type will be evaluated to true or false depending ...

  7. Conditional or Ternary Operator (?:) in C

    The conditional operator in C is kind of similar to the if-else statement as it follows the same algorithm as of if-else statement but the conditional operator takes less space and helps to write the if-else statements in the shortest way possible. It is also known as the ternary operator in C as it operates on three operands.. Syntax of Conditional/Ternary Operator in C

  8. C Conditional Statement: IF, IF Else and Nested IF Else with Example

    This process is called decision making in 'C.'. In 'C' programming conditional statements are possible with the help of the following two constructs: 1. If statement. 2. If-else statement. It is also called as branching as a program decides which statement to execute based on the result of the evaluated condition.

  9. C if...else Statement

    How if statement works? The if statement evaluates the test expression inside the parenthesis ().. If the test expression is evaluated to true, statements inside the body of if are executed.; If the test expression is evaluated to false, statements inside the body of if are not executed.; Working of if Statement

  10. c

    Rather, your code is always assigning B to A, and it is moreover checking whether the value of B (and thus also A) is equal to 1.. There's nothing "legacy" about this, this is generally a pretty handy idiom if you need the result of an operation but also want to check for errors:

  11. C If ... Else Conditions

    You can use these conditions to perform different actions for different decisions. C has the following conditional statements: Use if to specify a block of code to be executed, if a specified condition is true. Use else to specify a block of code to be executed, if the same condition is false. Use else if to specify a new condition to test, if ...

  12. if statement

    Conditionally executes code. Used where code needs to be executed only if some condition is true.

  13. if statement

    Explanation. If the condition yields true after conversion to bool, statement-true is executed.. If the else part of the if statement is present and condition yields false after conversion to bool, statement-false is executed.. In the second form of if statement (the one including else), if statement-true is also an if statement then that inner if statement must contain an else part as well ...

  14. Assignment operators

    Assignment performs implicit conversion from the value of rhs to the type of lhs and then replaces the value in the object designated by lhs with the converted value of rhs . Assignment also returns the same value as what was stored in lhs (so that expressions such as a = b = c are possible). The value category of the assignment operator is non ...

  15. bugprone-assignment-in-if-condition

    Finds assignments within conditions of if statements. Such assignments are bug-prone because they may have been intended as equality tests. This check finds all assignments within if conditions, including ones that are not flagged by -Wparentheses due to an extra set of parentheses, and including assignments that call an overloaded operator= ().

  16. Why would you use an assignment in a condition?

    The reason is: Performance improvement (sometimes) Less code (always) Take an example: There is a method someMethod() and in an if condition you want to check whether the return value of the method is null. If not, you are going to use the return value again. If(null != someMethod()){. String s = someMethod();

  17. Assignment Operators in C

    1. "=": This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example: a = 10; b = 20; ch = 'y'; 2. "+=": This operator is combination of '+' and '=' operators. This operator first adds the current value of the variable on left to the value on the right and ...

  18. If else programming exercises and solutions in C

    If else programming exercises and solutions in C. if...else is a branching statement. It is used to take an action based on some condition. For example - if user inputs valid account number and pin, then allow money withdrawal. If statement works like "If condition is met, then execute the task". It is used to compare things and take some ...

  19. C++ If...else (With Examples)

    In computer programming, we use the if...else statement to run one block of code under certain conditions and another block of code under different conditions.. For example, assigning grades (A, B, C) based on marks obtained by a student. if the percentage is above 90, assign grade A; if the percentage is above 75, assign grade B; if the percentage is above 65, assign grade C

  20. Israel urges people to evacuate parts of eastern Rafah "immediately

    Israel's military has issued a call for residents of eastern Rafah to "evacuate immediately," a day after the country's defense minister told troops inside Gaza to expect "intense action ...

  21. c

    The first getchar() loop gets a warning from GCC; the latter two do not because of the the explicit test of the value from the assignment. The people who write a condition like this: while ((c = getchar())) really annoy me. It avoids the warning from GCC, but it is not (IMNSHO) a good way of coding. edited May 30, 2012 at 5:00.

  22. Brittney Griner considered suicide while imprisoned in Russia

    May 2, 2024, 9:26 AM PDT. By Curtis Bunn. Brittney Griner, the WNBA star who spent nearly 10 months in a Russian prison two years ago, said she contemplated suicide in the early days of her ...

  23. Assignment operator works fine as a condition in if Statement in C

    I am aware that when a non zero value is provided as a condition in an if statement, the condition is evaluated to be true. Yet, I'm wondering how an assignment(=) is evaluated to be true here, instead of a comparison(==), and runs without any errors in the below C program.

  24. Rangers' Max Scherzer scratched from 2nd scheduled rehab start because

    Updated 8:43 PM PDT, April 30, 2024. ARLINGTON, Texas (AP) — Texas Rangers right-hander Max Scherzer was scratched from his second scheduled rehab start Tuesday because of thumb soreness. The soreness is similar to what Scherzer experienced last year before being sidelined for the end of the regular season and the start of the playoffs for ...