a=int(input("Enter A: "))b=int(input("Enter B: "))ifa>b:g=aelse:g=bprint("Greater = ",g) Output Enter A: 36 Enter B: 24 Greater = 36 Example 3: Find largest of two numbers using single statement a=int(input("Enter A: "))b=int(input("Enter B: "))c=aifa>belsebprint("Greater = ",c) Output Enter A:...
if (conditional expression){ //if true this block of code is executed }else{ //if a false block of code is executed } Example for the if-else statement package main import "fmt" func main() { var numerVariable = 10 if numerVariable%2 == 0 { fmt.Printf("Event Number if block ...
+---+ | Condition | +---|---+ | +---v---+ | If true | | statement | +---|---+ | +---v---+ | Else | | statement | +---+ Example: #include <stdio.h> int main() { int num = 10; if (num > 5) { printf("The number is greater than 5.n"); } else { ...
Code Example:#include <iostream> using namespace std; int main() { int marks = 28; // Initiating if-else statement if (marks > 40) { cout << "Student has passed"; } else { cout << "Student has failed"; } return 0; }
if(condition){Statement(s);}else{Statement(s);} The statements inside “if” would execute if the condition is true, and the statements inside “else” would execute if the condition is false. Example of if-else statement publicclassIfElseExample{publicstaticvoidmain(Stringargs[]){intnum=120...
Example: Python if…else Statementnumber = int(input('Enter a number: ')) if number > 0: print('Positive number') else: print('Not a positive number') print('This statement always executes') Run Code Sample Output 1Enter a number: 10 Positive number This statement always executes...
ELSE Statements; //gets executed only if all the provided conditions retrieve false. END IF; Example #1: How to Use IF-THEN-ELSIF Statement in Postgres? Let’s create two variables and assign them some random values: DO $$ DECLARE
Awk Simple If statement Awk If-Else statement Awk If-ElseIf-Ladder Awk Simple If Statement Single Action:Simple If statement is used to check the conditions, if the condition returns true, it performs its corresponding action(s). Syntax: ...
Example 2: Swift if...else Statement let number = 10 if (number > 0) { print("Number is positive.") } else { print("Number is negative.") } print("This statement is always executed.") Output Number is positive. This statement is always executed. In the above example, we have cre...
Ladder if-else statement example in C++: program to enter a character and validate whether it is an alphabet or digit, here we are using ladder if-else (multiple if-else) form of conditional statements in C++.