Kod yazarken sıklıkla kullanılan koşul belirteçleri, duruma bağlı olarak işlemler yapmamıza olanak sağlar. Genel yapıları 3 şekildedir:
1. if ( koşul ) - koşul gerçekleşirse komut uygulanır.
2. if ( koşul ) else ... - koşul gerçekleşmez ise ELSE'de belirtilenler uygulanır.
3. if ( koşul ) else if (koşul ) else ... - İlk koşul gerçekleşmezse alternatif koşullar else if ile belirtilebilir.
Aşağıdaki örnekte $islem 4 değerini alır, koşul cümlesi olarak yazdığımızda php bize bu yargının doğru olduğunu echo da belirttiğimiz cümle ile gösterir:
<?php
$islem = 2 + 2;
if ( $islem == 4 ) {
echo "2 + 2, 4 eder!";
}
?>
NOT: Koşul gerçekleşirse yapılacaklar { ... } şeklinde belirtilir. Ancak yapılacak iş tek satırlık ise direkt altına yazarak işlem yaptırtabiliriz:
<?php
$islem = 2 + 2;
if ( $islem == 4 )
echo "2 + 2, 4 eder!";
?>
Aşağıdaki örnekte koşul gerçekleşmezse ELSE ile php'ye ne yapacağını söylüyoruz:
<?php
$benim_sayim = 5;
if ( $benim_sayim == 4 )
echo "Benim sayım 4!";
else
echo "Benim sayım 4'ten farklı!";
?>
Ve son olarak araya bir koşul daha alarak yukarıda 3. yapıda bahsettiğimiz ELSE IF kullanımına bakıyoruz:
<?php
$sayi_tut = 6;
if ( $sayi_tut < 5 )
echo "Sayım 5'den küçük!";
else if ( $sayi_tut > 5 )
echo "Sayım 5'den büyük!";
else
echo "Sayım 5!";
?>
<?php
echo Karesi( 6 );
function Karesi( $sayi ) {
return $sayi * $sayi;
}
?>
Bu örnekte gördüğümüz fonksiyonun döndürdüğü değer sayısaldır, bir fonksiyon sayısal, alfasayısal (string), mantıksal (boolean) veya dize (array) döndürebilir. Ayrıca bir fonksiyonun işlevini kesip tekrar ana kodlara dönmesi için boş bir şekilde return; kullanılabilir.
<?php
echo "Benim adım ";
AdYaz( "Murat" );
echo "Kardeşimin adı ";
AdYaz( "Çiğdem" );
function AdYaz( $ad ) {
echo $ad . "<br />";
}
?>
The old crocodile was floating at the
river’s edge when a younger crocodile swam up next to him,
“I’ve heard
from many that you’re the fiercest hunter in all of the river bottoms. Please,
teach me your ways.”
Awoken from a
nice long afternoon nap, the old crocodile glanced at the young crocodile with
one of his reptilian eyes, said nothing and then fell back asleep atop the
water.
Feeling frustrated and disrespected,
the young crocodile swam off upriver to chase after some catfish, leaving
behind a flurry of bubbles. “I’ll show him,” he thought to
himself.
Later that day the young crocodile
returned to the old crocodile who was still napping and began to brag to him
about his successful hunt,
“I caught two
meaty catfish today. What have you caught? Nothing? Perhaps you’re not so
fierce after all.”
Unphased the old crocodile again
looked at the young crocodile, said nothing, closed his eyes and continued to
float atop the water as tiny minnows muched away lightly at the algae on his
underbelly.
Again, the young crocodile was angry
he couldn’t get a response from the elder, and he swam off a second time
upstream to see what he could hunt.
After a few hours of thrashing about
he was able to hunt down a small crane. Smiling, he kept the bird in his jaws
and swam back to the old crocodile, adamant about showing him who the true
hunter was.
As the young crocodile rounded the
bend, he saw the elder crocodile still floating in the same spot near the
river’s edge.
However, something had changed — a
large wildebeest was enjoying an afternoon drink just inches near the old
crocodile’s head.
In one lightning-fast movement, the
old crocodile bolted out of the water, wrapped his jaws around the great
wildebeest and pulled him under the river.
Awestruck the young crocodile swam up
with the tiny bird hanging from his mouth and watched as the old crocodile
enjoyed his 500 lb meal.
The young crocodile asked him, “Please…
tell me… how… how did you do that?”
Through mouthfuls of wildebeest, the
old crocodile finally responded,
“I did
nothing.”
Doing what matters vs. busy-bragging
When I was first building JotForm, I was a lot like
the young crocodile — believing that I always had to be doing something
to get results.
Back then, if someone would have told
me that I would see greater results by spending more time doing nothing, I
would have rolled my eyes and continued to chip away at my 16 hour day of work.
I thought that in order to be
successful, I had to constantly be building, working, growing and developing
the next thing — whatever that “thing” was.
All of us have a problem with
busyness. But being busy and being successful are not one and the same. And, I
think if we were to make “doing nothing” more of a priority, we might find
ourselves catching more wildebeests versus measly catfish.
It worked for me, and I hope it can work for you, too.
But, doing less or nothing at
all is easier said than done, especially in a society that suffers
from extreme busyness. Let’s take a closer look at our unhealthy
obsession with staying busy…
The extreme busyness epidemic.
Mankind has struggled with busyness
since the beginning of time — or at least since 425 BC when Homer
walked the Earth.
The
Odyssey tells the tale of the Lotus-eaters — a strange people that
slothed around all day long eating lotus and doing nothing. And,
what was stranger than fiction was that these people were content with their
lives.
Homer wrote that after some of
Odysseus’s crew ate the Lotus-eaters Lotus fruit (say that three times fast),
they became like the Lotus-eaters — content, relaxed and a bit
lethargic.
Terrified that if all of his men ate
the lotus fruit they would be unmotivated to return home, Odysseus ordered the
affected men to be tied to the ship benches and for the ship to set sail
immediately.
It’s interesting, Odysseus’s
reaction to this feeling of “doing nothing”sounds similar to the Corporate
CEO, the Startup Founder and the collegiate football coach we know today
— hardcore workaholics that despise anything that might
allude to a sense of complacency.
Though, they of course are just the
tip of a much larger societal iceberg that feels frozen with fear at the
thought of doing nothing.
The world as a whole now measures
value in terms of busyness versus quality of work. In many ways, it has become
something of a status symbol to be “busy”.
How many times have you heard or
had a conversation like this…
“How have you
been lately, Mark?”
“Oh man, just
insanely busy!”
“That’s
awesome to hear man — keep killing it!”
We’ve grown to subconsciously measure
a person’s worth based off how many hours they work, how much is on their plate
and put simply — whether or not they are running around like a chicken
with their head cut off.
In Tim Ferriss’s 4-Hour Work Week, he
pokes fun at this idea by facetiously saying that if you want a promotion, you
should appear to be more busy by working longer hours, scrambling around and
constantly answering emails.
But, sooner or later, all of us have
to ask ourselves what our mission is — is it to be the busiest or is it
to make
the most impact?
And, what’s fascinating is that when
we look at some of the greatest minds to grace planet Earth, we see an
interesting commonality — they all make time for doing nothing.
The power of doing nothing at all
Making time in your life to do nothing
can be challenging — especially during the workweek where we are constantly
pummeled and bombarded with meetings, notifications and an ever-growing list of
tasks.
Busy founders have started
implementing “Think Weeks” into their annual schedules — week-long periods they
spend reflecting, reading, thinking and living outside the all-encapsulating
world that is running a business.
While young founders like Skillshare’s
Mike Karnjanaprakorn have adopted this practice, as well as big names like Steve
Jobs, Mark Zuckerberg and Tim Ferriss, it was Bill Gates who originally made
the Think Weekfamous.
For many years while running
Microsoft, Gates would retreat into week-long Think Weeks twice
a year — not vacations, but actual periods of time dedicated to doing nothing.
Gates was so adamant about his Think
Weeks that family, friends and Microsoft employees were banned. Today,
Gates attributes much of Microsoft’s success to the big ideas and concepts he
stumbled upon while doing nothing.
On implementing “nothing” time.
You don’t necessarily have to ban
family and friends to retreat into a Think Week, though. Take
me as an example.
Every year, I
take at least a full week off from my company and head back to my
hometown to help my parents with the olive harvest.
All thoughts of startup growth or conversion rates slip away when
you’re picking olives. It’s meditative and calming.
I know that olive picking won’t land
me at the top of TechCrunch, but it’s a personal measure of success. And
somehow, some of my best ideas come to me during this period.
For someone who can’t take an entire
week off of work once a year to do nothing, I recommend taking a slightly
different approach — embracing the digital sabbath.
On either Saturday or Sunday, force
yourself to step away from all forms of technology — a practice known as a
digital sabbath.
Shut off your smartphone and hide it in your closet.
Powerdown the laptop and slide it under your bed. And, try with all
your might to refrain from binge-watching Netflix.
Give your brain space to think by
stepping away from the daily grind and doing nothing. Your mind will have time
to stumble upon new ideas and further process old ones.
You may find the success that results
from this practice to be similar to that of the old crocodile at the beginning
of this article.
While we tell ourselves we can achieve
more by scrambling, sometimes it’s better to close our eyes and just float.
And, wait, until the wildebeest shows
up.
Aytekin Tank,
Founder of Jotform.com