Home  >  Article  >  Java  >  What is the difference between if and while in java?

What is the difference between if and while in java?

青灯夜游
青灯夜游Original
2019-12-26 16:13:404536browse

What is the difference between if and while in java?

#What is the difference between if and while in java?

while and if have different usages. One is a loop statement and the other is a judgment statement.

if is a judgment. If the following conditions are met, it will continue to run the things in the if statement. If it is not met, it will jump out and execute the else statement or the following statement.

while is a loop statement. When the condition in while is met, the loop body inside will be executed until the condition is not met.

The structure of the linked list needs to be read continuously until the entire linked list structure is read, so a while; if is only read once and then jumped out.

if and while both skip the code block and execute the following code when the condition is not true.

The difference is that when the condition is established, if executes the code block and then continues to execute the following code. After executing the while code block, the while condition is judged. If it is established, the code in the code block will be executed again until it is not established. , the code following the code block is executed. If the break; instruction is encountered in the while code block, the while code block will be jumped out and the following code will be executed directly.

Recommended learning: Java video tutorial

The above is the detailed content of What is the difference between if and while in java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn