Flow Controls shows the execution flow of the program.
Flow Controls describes that the order in which the statement will be executed at run -time.
Flow Control is divided into 3 parts:-
- Selection Statement
- Iterative Statement
- Transfer Statement
1.Selection Statement:-
if else statement
Syntax
if(x)
{
if the condition is true where x should be Boolean
}
else
{
if the condition is false
}
1.The argument should be in the boolean . If we are taking any other than boolean we will get Compile -Time error.
example 1:-
if(8>2)
{
System.out.println("Condition is True:");
}
else
{
System.out.println("Condition is False:");
}
output is :Condition is True:
example 2:-
if(10)
{
System.out.println("Condition is True:");
}
else
{
System.out.println("Condition is False:");
}
Compile -Time Error: incompatible time
found : int
required : boolean
2.else part and curly braces { } are optional . without curly braces
{ } only one statement is allowed
which should not be the declarative statement.
example 1:
if(true)
System.out.println("Hello:"); valid;
example 2:
if(true) valid;
example 3:
if(true)
int x=10; invalid;
Compile Time Error.
example 4:
if(true)
{ valid;
int x=10;
}
Note: Nesting Of if -else is possible.
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home