Java Basics Tutorial – Part 5 – Conditional Statements

In this lesson of the Java Bascics Tutorial, we take a look at Conditional Statements.

 

conditional-statement-picA conditional statement is a piece of code that checks the given condition, and when it is true, the code related to it is performed. It is used to make decisions based on the conditions. Conditional statements execute when there is no condition around the statements. If you put a 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.

Conditional statements begin with the keyword if followed by parentheses. An expression is placed inside the parentheses, then evaluated when the conditional statement is reached. 

The parentheses are followed by a block, which is defined inside opening { and closing } curly brackets. The source code inside the block executes if the expression inside the parentheses evaluates to true. If the expression in the conditional statement evaluates to true, the execution of the program progresses to the block defined by the conditional statement.

On the other hand, if the expression evaluates to false, the execution moves on to the statement after the closing curly bracket of the current conditional statement. Using the else command, we create an alternative option for when the conditional expression evaluates to false. In the case of multiple conditions, we can use the else if  command. else if is like else, but with an additional condition. It follows the if-condition, and they may be multiple.switch-case-computer

To sum it up, conditional statements are something that you must learn if you want to continue developing as a programmer. They s are specified by a set of statements having boolean expressions which, are evaluated to a boolean value true or false. Conditional statements help us to make a decision based on certain conditions.

Lesson Topics

In this video we review the following topics:
  • Logical Expressions
  • Conditional Statements
  • Series of Checks
  • Variable Scope
  • Debugging

Practical Exercises

Watch the video and solve the problems. To better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

Leave a Comment

Recent Posts

About SoftUni

SoftUni provides high-quality education, profession and job to people who want to learn coding.

The SoftUni Global “Learn to Code” Community supports learners with free learning resources, mentorship and community help.

Tags

Categories