Can a programmer work without the if statement ?

All the programming is nothing but usage of loops and conditional statements. Entire programming is mainly based on
1. If statements
2. For loops

If you know these you can easily do programming. A good programmer is one who uses these things efficiently to reduce execution time with better readability and maintainable code. Can a programmer work without the if (conditional statements) ?
It is difficult but entire programming can be done with only For loop construct.

How ? well inside the for loop there is conditional statement which could be used wisely to avoid using if.

for ( initialization; conditional statement; update){
do some thing
}

String sex = “male”;
if(sex.equalsIgnoreCase(“male”)) {
System.out.println(“Man is the king “);
} else{
System.out.println(“WoMan is the Queen “);
}

lets say we need to convert this if structure in for loop.
            for(;sex.equalsIgnoreCase(“male”);){
                System.out.println(“Man is the king “);
            }
In first attempt it will be some like this but this will cause the infinite loop so we must have to put break after our job is over to break the loop.
            for(;sex.equalsIgnoreCase(“male”);){
                System.out.println(“Man is the king “);
                break;
            }

Now how to use the else  part of the if structure.
for(;!sex.equalsIgnoreCase(“male”);){
System.out.println(“WoMan is the Queen “);
break;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s