If statements are used in Ruby to determine if a statement or a block of statements will be performed or not, i.e. if a condition is true, a block of statements will be executed, otherwise not.
If the conditional is true, the code is executed. The code supplied in the otherwise clause is run if the conditional is not true. The reserved word then, a newline, or a semicolon separates the conditional part of an if statement from the code.
If a particular condition is true, the if/else statement executes a block of code. Another block of code can be performed if the condition is false. The if/else statement is part of Ruby's "Conditional" Statements, which are used to conduct various actions depending on certain situations.
If-then condition. A program determines which statement to execute based on the result of the assessed condition, which is also known as branching.
The if-else condition is used to execute both the true and false parts of a condition. The if block code is run if the condition is true, and the else block code is executed if the condition is false.
Share a personalized message with your friends.